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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, 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 typedef struct _GstTagListImpl
59 GstStructure *structure;
63 #define GST_TAG_LIST_STRUCTURE(taglist) ((GstTagListImpl*)(taglist))->structure
64 #define GST_TAG_LIST_SCOPE(taglist) ((GstTagListImpl*)(taglist))->scope
68 GType type; /* type the data is in */
70 const gchar *nick; /* translated short description */
71 const gchar *blurb; /* translated long description */
73 GstTagMergeFunc merge_func; /* functions to merge the values */
74 GstTagFlag flag; /* type of tag */
75 GQuark name_quark; /* quark for the name */
79 #define g_value_get_char g_value_get_schar
81 static GMutex __tag_mutex;
82 #define TAG_LOCK g_mutex_lock (&__tag_mutex)
83 #define TAG_UNLOCK g_mutex_unlock (&__tag_mutex)
85 /* tags hash table: maps tag name string => GstTagInfo */
86 static GHashTable *__tags;
88 GST_DEFINE_MINI_OBJECT_TYPE (GstTagList, gst_tag_list);
90 static void __gst_tag_list_free (GstTagList * list);
91 static GstTagList *__gst_tag_list_copy (const GstTagList * list);
94 * g_value_register_transform_func (_gst_tag_list_type, G_TYPE_STRING,
95 * _gst_structure_transform_to_string);
98 _priv_gst_tag_initialize (void)
100 g_mutex_init (&__tag_mutex);
102 __tags = g_hash_table_new (g_str_hash, g_str_equal);
103 gst_tag_register_static (GST_TAG_TITLE, GST_TAG_FLAG_META,
105 _("title"), _("commonly used title"), gst_tag_merge_strings_with_comma);
106 gst_tag_register_static (GST_TAG_TITLE_SORTNAME, GST_TAG_FLAG_META,
108 _("title sortname"), _("commonly used title for sorting purposes"), NULL);
109 gst_tag_register_static (GST_TAG_ARTIST, GST_TAG_FLAG_META,
112 _("person(s) responsible for the recording"),
113 gst_tag_merge_strings_with_comma);
114 gst_tag_register_static (GST_TAG_ARTIST_SORTNAME, GST_TAG_FLAG_META,
116 _("artist sortname"),
117 _("person(s) responsible for the recording for sorting purposes"), NULL);
118 gst_tag_register_static (GST_TAG_ALBUM, GST_TAG_FLAG_META,
121 _("album containing this data"), gst_tag_merge_strings_with_comma);
122 gst_tag_register_static (GST_TAG_ALBUM_SORTNAME, GST_TAG_FLAG_META,
125 _("album containing this data for sorting purposes"), NULL);
126 gst_tag_register_static (GST_TAG_ALBUM_ARTIST, GST_TAG_FLAG_META,
129 _("The artist of the entire album, as it should be displayed"),
130 gst_tag_merge_strings_with_comma);
131 gst_tag_register_static (GST_TAG_ALBUM_ARTIST_SORTNAME, GST_TAG_FLAG_META,
133 _("album artist sortname"),
134 _("The artist of the entire album, as it should be sorted"), NULL);
135 gst_tag_register_static (GST_TAG_DATE, GST_TAG_FLAG_META, G_TYPE_DATE,
136 _("date"), _("date the data was created (as a GDate structure)"), NULL);
137 gst_tag_register_static (GST_TAG_DATE_TIME, GST_TAG_FLAG_META,
138 GST_TYPE_DATE_TIME, _("datetime"),
139 _("date and time the data was created (as a GstDateTime structure)"),
141 gst_tag_register_static (GST_TAG_GENRE, GST_TAG_FLAG_META,
144 _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
145 gst_tag_register_static (GST_TAG_COMMENT, GST_TAG_FLAG_META,
148 _("free text commenting the data"), gst_tag_merge_use_first);
149 gst_tag_register_static (GST_TAG_EXTENDED_COMMENT, GST_TAG_FLAG_META,
151 _("extended comment"),
152 _("free text commenting the data in key=value or key[en]=comment form"),
153 gst_tag_merge_use_first);
154 gst_tag_register_static (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
157 _("track number inside a collection"), gst_tag_merge_use_first);
158 gst_tag_register_static (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
161 _("count of tracks inside collection this track belongs to"),
162 gst_tag_merge_use_first);
163 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
166 _("disc number inside a collection"), gst_tag_merge_use_first);
167 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
170 _("count of discs inside collection this disc belongs to"),
171 gst_tag_merge_use_first);
172 gst_tag_register_static (GST_TAG_LOCATION, GST_TAG_FLAG_META,
174 _("location"), _("Origin of media as a URI (location, where the "
175 "original of the file or stream is hosted)"),
176 gst_tag_merge_strings_with_comma);
177 gst_tag_register_static (GST_TAG_HOMEPAGE, GST_TAG_FLAG_META,
180 _("Homepage for this media (i.e. artist or movie homepage)"),
181 gst_tag_merge_strings_with_comma);
182 gst_tag_register_static (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
183 G_TYPE_STRING, _("description"),
184 _("short text describing the content of the data"),
185 gst_tag_merge_strings_with_comma);
186 gst_tag_register_static (GST_TAG_VERSION, GST_TAG_FLAG_META, G_TYPE_STRING,
187 _("version"), _("version of this data"), NULL);
188 gst_tag_register_static (GST_TAG_ISRC, GST_TAG_FLAG_META, G_TYPE_STRING,
191 ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
193 /* FIXME: organization (fix what? tpm) */
194 gst_tag_register_static (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META,
195 G_TYPE_STRING, _("organization"), _("organization"),
196 gst_tag_merge_strings_with_comma);
197 gst_tag_register_static (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
198 G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
199 gst_tag_register_static (GST_TAG_COPYRIGHT_URI, GST_TAG_FLAG_META,
200 G_TYPE_STRING, _("copyright uri"),
201 _("URI to the copyright notice of the data"), NULL);
202 gst_tag_register_static (GST_TAG_ENCODED_BY, GST_TAG_FLAG_META, G_TYPE_STRING,
203 _("encoded by"), _("name of the encoding person or organization"),
204 gst_tag_merge_strings_with_comma);
205 gst_tag_register_static (GST_TAG_CONTACT, GST_TAG_FLAG_META,
207 _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
208 gst_tag_register_static (GST_TAG_LICENSE, GST_TAG_FLAG_META,
209 G_TYPE_STRING, _("license"), _("license of data"), NULL);
210 gst_tag_register_static (GST_TAG_LICENSE_URI, GST_TAG_FLAG_META,
211 G_TYPE_STRING, _("license uri"),
212 _("URI to the license of the data"), NULL);
213 gst_tag_register_static (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
216 _("person(s) performing"), gst_tag_merge_strings_with_comma);
217 gst_tag_register_static (GST_TAG_COMPOSER, GST_TAG_FLAG_META,
220 _("person(s) who composed the recording"),
221 gst_tag_merge_strings_with_comma);
222 gst_tag_register_static (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
224 _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
225 gst_tag_register_static (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
228 _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
229 gst_tag_register_static (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
231 _("video codec"), _("codec the video data is stored in"), NULL);
232 gst_tag_register_static (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
234 _("audio codec"), _("codec the audio data is stored in"), NULL);
235 gst_tag_register_static (GST_TAG_SUBTITLE_CODEC, GST_TAG_FLAG_ENCODED,
237 _("subtitle codec"), _("codec the subtitle data is stored in"), NULL);
238 gst_tag_register_static (GST_TAG_CONTAINER_FORMAT, GST_TAG_FLAG_ENCODED,
239 G_TYPE_STRING, _("container format"),
240 _("container format the data is stored in"), NULL);
241 gst_tag_register_static (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
242 G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
243 gst_tag_register_static (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
244 G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
245 gst_tag_register_static (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
246 G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
247 gst_tag_register_static (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
248 G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
249 gst_tag_register_static (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
251 _("encoder"), _("encoder used to encode this stream"), NULL);
252 gst_tag_register_static (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
254 _("encoder version"),
255 _("version of the encoder used to encode this stream"), NULL);
256 gst_tag_register_static (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
257 G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
258 gst_tag_register_static (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
259 G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
260 gst_tag_register_static (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
261 G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
262 gst_tag_register_static (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
263 G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
264 gst_tag_register_static (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
265 G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
266 gst_tag_register_static (GST_TAG_REFERENCE_LEVEL, GST_TAG_FLAG_META,
267 G_TYPE_DOUBLE, _("replaygain reference level"),
268 _("reference level of track and album gain values"), NULL);
269 gst_tag_register_static (GST_TAG_LANGUAGE_CODE, GST_TAG_FLAG_META,
270 G_TYPE_STRING, _("language code"),
271 _("language code for this stream, conforming to ISO-639-1 or ISO-639-2"),
273 gst_tag_register_static (GST_TAG_LANGUAGE_NAME, GST_TAG_FLAG_META,
274 G_TYPE_STRING, _("language name"),
275 _("freeform name of the language this stream is in"), NULL);
276 gst_tag_register_static (GST_TAG_IMAGE, GST_TAG_FLAG_META, GST_TYPE_SAMPLE,
277 _("image"), _("image related to this stream"), gst_tag_merge_use_first);
278 gst_tag_register_static (GST_TAG_PREVIEW_IMAGE, GST_TAG_FLAG_META,
280 /* TRANSLATORS: 'preview image' = image that shows a preview of the full image */
281 _("preview image"), _("preview image related to this stream"), NULL);
282 gst_tag_register_static (GST_TAG_ATTACHMENT, GST_TAG_FLAG_META,
283 GST_TYPE_SAMPLE, _("attachment"), _("file attached to this stream"),
284 gst_tag_merge_use_first);
285 gst_tag_register_static (GST_TAG_BEATS_PER_MINUTE, GST_TAG_FLAG_META,
286 G_TYPE_DOUBLE, _("beats per minute"),
287 _("number of beats per minute in audio"), NULL);
288 gst_tag_register_static (GST_TAG_KEYWORDS, GST_TAG_FLAG_META, G_TYPE_STRING,
289 _("keywords"), _("comma separated keywords describing the content"),
290 gst_tag_merge_strings_with_comma);
291 gst_tag_register_static (GST_TAG_GEO_LOCATION_NAME, GST_TAG_FLAG_META,
292 G_TYPE_STRING, _("geo location name"),
293 _("human readable descriptive location of where "
294 "the media has been recorded or produced"), NULL);
295 gst_tag_register_static (GST_TAG_GEO_LOCATION_LATITUDE, GST_TAG_FLAG_META,
296 G_TYPE_DOUBLE, _("geo location latitude"),
297 _("geo latitude location of where the media has been recorded or "
298 "produced in degrees according to WGS84 (zero at the equator, "
299 "negative values for southern latitudes)"), NULL);
300 gst_tag_register_static (GST_TAG_GEO_LOCATION_LONGITUDE, GST_TAG_FLAG_META,
301 G_TYPE_DOUBLE, _("geo location longitude"),
302 _("geo longitude location of where the media has been recorded or "
303 "produced in degrees according to WGS84 (zero at the prime meridian "
304 "in Greenwich/UK, negative values for western longitudes)"), NULL);
305 gst_tag_register_static (GST_TAG_GEO_LOCATION_ELEVATION, GST_TAG_FLAG_META,
306 G_TYPE_DOUBLE, _("geo location elevation"),
307 _("geo elevation of where the media has been recorded or produced in "
308 "meters according to WGS84 (zero is average sea level)"), NULL);
309 gst_tag_register_static (GST_TAG_GEO_LOCATION_COUNTRY, GST_TAG_FLAG_META,
310 G_TYPE_STRING, _("geo location country"),
311 _("country (english name) where the media has been recorded "
312 "or produced"), NULL);
313 gst_tag_register_static (GST_TAG_GEO_LOCATION_CITY, GST_TAG_FLAG_META,
314 G_TYPE_STRING, _("geo location city"),
315 _("city (english name) where the media has been recorded "
316 "or produced"), NULL);
317 gst_tag_register_static (GST_TAG_GEO_LOCATION_SUBLOCATION, GST_TAG_FLAG_META,
318 G_TYPE_STRING, _("geo location sublocation"),
319 _("a location within a city where the media has been produced "
320 "or created (e.g. the neighborhood)"), NULL);
321 gst_tag_register_static (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR,
322 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location horizontal error"),
323 _("expected error of the horizontal positioning measures (in meters)"),
325 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED,
326 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement speed"),
327 _("movement speed of the capturing device while performing the capture "
329 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION,
330 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement direction"),
331 _("indicates the movement direction of the device performing the capture"
332 " of a media. It is represented as degrees in floating point "
333 "representation, 0 means the geographic north, and increases "
335 gst_tag_register_static (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION,
336 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location capture direction"),
337 _("indicates the direction the device is pointing to when capturing "
338 " a media. It is represented as degrees in floating point "
339 " representation, 0 means the geographic north, and increases "
341 gst_tag_register_static (GST_TAG_SHOW_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
342 /* TRANSLATORS: 'show name' = 'TV/radio/podcast show name' here */
344 _("Name of the tv/podcast/series show the media is from"),
345 gst_tag_merge_strings_with_comma);
346 gst_tag_register_static (GST_TAG_SHOW_SORTNAME, GST_TAG_FLAG_META,
348 /* TRANSLATORS: 'show sortname' = 'TV/radio/podcast show name as used for sorting purposes' here */
350 _("Name of the tv/podcast/series show the media is from, for sorting "
352 gst_tag_register_static (GST_TAG_SHOW_EPISODE_NUMBER, GST_TAG_FLAG_META,
353 G_TYPE_UINT, _("episode number"),
354 _("The episode number in the season the media is part of"),
355 gst_tag_merge_use_first);
356 gst_tag_register_static (GST_TAG_SHOW_SEASON_NUMBER, GST_TAG_FLAG_META,
357 G_TYPE_UINT, _("season number"),
358 _("The season number of the show the media is part of"),
359 gst_tag_merge_use_first);
360 gst_tag_register_static (GST_TAG_LYRICS, GST_TAG_FLAG_META, G_TYPE_STRING,
361 _("lyrics"), _("The lyrics of the media, commonly used for songs"),
362 gst_tag_merge_strings_with_comma);
363 gst_tag_register_static (GST_TAG_COMPOSER_SORTNAME, GST_TAG_FLAG_META,
364 G_TYPE_STRING, _("composer sortname"),
365 _("person(s) who composed the recording, for sorting purposes"), NULL);
366 gst_tag_register_static (GST_TAG_GROUPING, GST_TAG_FLAG_META, G_TYPE_STRING,
368 _("Groups related media that spans multiple tracks, like the different "
369 "pieces of a concerto. It is a higher level than a track, "
370 "but lower than an album"), NULL);
371 gst_tag_register_static (GST_TAG_USER_RATING, GST_TAG_FLAG_META, G_TYPE_UINT,
373 _("Rating attributed by a user. The higher the rank, "
374 "the more the user likes this media"), NULL);
375 gst_tag_register_static (GST_TAG_DEVICE_MANUFACTURER, GST_TAG_FLAG_META,
376 G_TYPE_STRING, _("device manufacturer"),
377 _("Manufacturer of the device used to create this media"), NULL);
378 gst_tag_register_static (GST_TAG_DEVICE_MODEL, GST_TAG_FLAG_META,
379 G_TYPE_STRING, _("device model"),
380 _("Model of the device used to create this media"), NULL);
381 gst_tag_register_static (GST_TAG_APPLICATION_NAME, GST_TAG_FLAG_META,
382 G_TYPE_STRING, _("application name"),
383 _("Application used to create the media"), NULL);
384 gst_tag_register_static (GST_TAG_APPLICATION_DATA, GST_TAG_FLAG_META,
385 GST_TYPE_SAMPLE, _("application data"),
386 _("Arbitrary application data to be serialized into the media"), NULL);
387 gst_tag_register_static (GST_TAG_IMAGE_ORIENTATION, GST_TAG_FLAG_META,
388 G_TYPE_STRING, _("image orientation"),
389 _("How the image should be rotated or flipped before display"), NULL);
393 * gst_tag_merge_use_first:
394 * @dest: (out caller-allocates): uninitialized GValue to store result in
395 * @src: GValue to copy from
397 * This is a convenience function for the func argument of gst_tag_register().
398 * It creates a copy of the first value from the list.
401 gst_tag_merge_use_first (GValue * dest, const GValue * src)
403 const GValue *ret = gst_value_list_get_value (src, 0);
405 g_value_init (dest, G_VALUE_TYPE (ret));
406 g_value_copy (ret, dest);
410 * gst_tag_merge_strings_with_comma:
411 * @dest: (out caller-allocates): uninitialized GValue to store result in
412 * @src: GValue to copy from
414 * This is a convenience function for the func argument of gst_tag_register().
415 * It concatenates all given strings using a comma. The tag must be registered
416 * as a G_TYPE_STRING or this function will fail.
419 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
424 count = gst_value_list_get_size (src);
425 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
426 for (i = 1; i < count; i++) {
427 /* separator between two strings */
428 g_string_append (str, _(", "));
429 g_string_append (str,
430 g_value_get_string (gst_value_list_get_value (src, i)));
433 g_value_init (dest, G_TYPE_STRING);
434 g_value_take_string (dest, str->str);
435 g_string_free (str, FALSE);
439 gst_tag_lookup (const gchar * tag_name)
444 ret = g_hash_table_lookup (__tags, (gpointer) tag_name);
452 * @name: the name or identifier string
453 * @flag: a flag describing the type of tag info
454 * @type: the type this data is in
455 * @nick: human-readable name
456 * @blurb: a human-readable description about this tag
457 * @func: (allow-none): function for merging multiple values of this tag, or NULL
459 * Registers a new tag type for the use with GStreamer's type system. If a type
460 * with that name is already registered, that one is used.
461 * The old registration may have used a different type however. So don't rely
462 * on your supplied values.
464 * Important: if you do not supply a merge function the implication will be
465 * that there can only be one single value for this tag in a tag list and
466 * any additional values will silenty be discarded when being added (unless
467 * #GST_TAG_MERGE_REPLACE, #GST_TAG_MERGE_REPLACE_ALL, or
468 * #GST_TAG_MERGE_PREPEND is used as merge mode, in which case the new
469 * value will replace the old one in the list).
471 * The merge function will be called from gst_tag_list_copy_value() when
472 * it is required that one or more values for a tag be condensed into
473 * one single value. This may happen from gst_tag_list_get_string(),
474 * gst_tag_list_get_int(), gst_tag_list_get_double() etc. What will happen
475 * exactly in that case depends on how the tag was registered and if a
476 * merge function was supplied and if so which one.
478 * Two default merge functions are provided: gst_tag_merge_use_first() and
479 * gst_tag_merge_strings_with_comma().
482 gst_tag_register (const gchar * name, GstTagFlag flag, GType type,
483 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
485 g_return_if_fail (name != NULL);
486 g_return_if_fail (nick != NULL);
487 g_return_if_fail (blurb != NULL);
488 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
490 return gst_tag_register_static (g_intern_string (name), flag, type,
491 g_intern_string (nick), g_intern_string (blurb), func);
495 * gst_tag_register_static:
496 * @name: the name or identifier string (string constant)
497 * @flag: a flag describing the type of tag info
498 * @type: the type this data is in
499 * @nick: human-readable name or short description (string constant)
500 * @blurb: a human-readable description for this tag (string constant)
501 * @func: (allow-none): function for merging multiple values of this tag, or NULL
503 * Registers a new tag type for the use with GStreamer's type system.
505 * Same as gst_tag_register(), but @name, @nick, and @blurb must be
506 * static strings or inlined strings, as they will not be copied. (GStreamer
507 * plugins will be made resident once loaded, so this function can be used
508 * even from dynamically loaded plugins.)
511 gst_tag_register_static (const gchar * name, GstTagFlag flag, GType type,
512 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
516 g_return_if_fail (name != NULL);
517 g_return_if_fail (nick != NULL);
518 g_return_if_fail (blurb != NULL);
519 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
521 info = gst_tag_lookup (name);
524 g_return_if_fail (info->type == type);
528 info = g_slice_new (GstTagInfo);
531 info->name_quark = g_quark_from_static_string (name);
534 info->merge_func = func;
537 g_hash_table_insert (__tags, (gpointer) name, info);
543 * @tag: name of the tag
545 * Checks if the given type is already registered.
547 * Returns: TRUE if the type is already registered
550 gst_tag_exists (const gchar * tag)
552 g_return_val_if_fail (tag != NULL, FALSE);
554 return gst_tag_lookup (tag) != NULL;
561 * Gets the #GType used for this tag.
563 * Returns: the #GType of this tag
566 gst_tag_get_type (const gchar * tag)
570 g_return_val_if_fail (tag != NULL, 0);
571 info = gst_tag_lookup (tag);
572 g_return_val_if_fail (info != NULL, 0);
581 * Returns the human-readable name of this tag, You must not change or free
584 * Returns: the human-readable name of this tag
587 gst_tag_get_nick (const gchar * tag)
591 g_return_val_if_fail (tag != NULL, NULL);
592 info = gst_tag_lookup (tag);
593 g_return_val_if_fail (info != NULL, NULL);
599 * gst_tag_get_description:
602 * Returns the human-readable description of this tag, You must not change or
605 * Returns: the human-readable description of this tag
608 gst_tag_get_description (const gchar * tag)
612 g_return_val_if_fail (tag != NULL, NULL);
613 info = gst_tag_lookup (tag);
614 g_return_val_if_fail (info != NULL, NULL);
623 * Gets the flag of @tag.
625 * Returns: the flag of this tag.
628 gst_tag_get_flag (const gchar * tag)
632 g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
633 info = gst_tag_lookup (tag);
634 g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
643 * Checks if the given tag is fixed. A fixed tag can only contain one value.
644 * Unfixed tags can contain lists of values.
646 * Returns: TRUE, if the given tag is fixed.
649 gst_tag_is_fixed (const gchar * tag)
653 g_return_val_if_fail (tag != NULL, FALSE);
654 info = gst_tag_lookup (tag);
655 g_return_val_if_fail (info != NULL, FALSE);
657 return info->merge_func == NULL;
660 /* takes ownership of the structure */
662 gst_tag_list_new_internal (GstStructure * s)
664 GstTagList *tag_list;
666 g_assert (s != NULL);
668 tag_list = (GstTagList *) g_slice_new (GstTagListImpl);
670 gst_mini_object_init (GST_MINI_OBJECT_CAST (tag_list), 0, GST_TYPE_TAG_LIST,
671 (GstMiniObjectCopyFunction) __gst_tag_list_copy, NULL,
672 (GstMiniObjectFreeFunction) __gst_tag_list_free);
674 GST_TAG_LIST_STRUCTURE (tag_list) = s;
675 GST_TAG_LIST_SCOPE (tag_list) = GST_TAG_SCOPE_STREAM;
677 #ifdef DEBUG_REFCOUNT
678 GST_CAT_TRACE (GST_CAT_TAGS, "created taglist %p", tag_list);
685 __gst_tag_list_free (GstTagList * list)
687 g_return_if_fail (GST_IS_TAG_LIST (list));
689 #ifdef DEBUG_REFCOUNT
690 GST_CAT_TRACE (GST_CAT_TAGS, "freeing taglist %p", list);
693 gst_structure_free (GST_TAG_LIST_STRUCTURE (list));
695 g_slice_free1 (sizeof (GstTagListImpl), list);
699 __gst_tag_list_copy (const GstTagList * list)
701 const GstStructure *s;
703 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
705 s = GST_TAG_LIST_STRUCTURE (list);
706 return gst_tag_list_new_internal (gst_structure_copy (s));
710 * gst_tag_list_new_empty:
712 * Creates a new empty GstTagList.
714 * Free-function: gst_tag_list_unref
716 * Returns: (transfer full): An empty tag list
719 gst_tag_list_new_empty (void)
722 GstTagList *tag_list;
724 s = gst_structure_new_id_empty (GST_QUARK (TAGLIST));
725 tag_list = gst_tag_list_new_internal (s);
732 * @...: NULL-terminated list of values to set
734 * Creates a new taglist and appends the values for the given tags. It expects
735 * tag-value pairs like gst_tag_list_add(), and a NULL terminator after the
736 * last pair. The type of the values is implicit and is documented in the API
737 * reference, but can also be queried at runtime with gst_tag_get_type(). It
738 * is an error to pass a value of a type not matching the tag type into this
739 * function. The tag list will make copies of any arguments passed
740 * (e.g. strings, buffers).
742 * After creation you might also want to set a #GstTagScope on the returned
743 * taglist to signal if the contained tags are global or stream tags. By
744 * default stream scope is assumes. See gst_tag_list_set_scope().
746 * Free-function: gst_tag_list_unref
748 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
749 * when no longer needed.
752 gst_tag_list_new (const gchar * tag, ...)
757 g_return_val_if_fail (tag != NULL, NULL);
759 list = gst_tag_list_new_empty ();
760 va_start (args, tag);
761 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
768 * gst_tag_list_new_valist:
769 * @var_args: tag / value pairs to set
771 * Just like gst_tag_list_new(), only that it takes a va_list argument.
772 * Useful mostly for language bindings.
774 * Free-function: gst_tag_list_unref
776 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
777 * when no longer needed.
780 gst_tag_list_new_valist (va_list var_args)
785 list = gst_tag_list_new_empty ();
787 tag = va_arg (var_args, gchar *);
788 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
794 * gst_tag_list_set_scope:
795 * @list: a #GstTagList
796 * @scope: new scope for @list
798 * Sets the scope of @list to @scope. By default the scope
799 * of a taglist is stream scope.
803 gst_tag_list_set_scope (GstTagList * list, GstTagScope scope)
805 g_return_if_fail (GST_IS_TAG_LIST (list));
806 g_return_if_fail (gst_tag_list_is_writable (list));
808 GST_TAG_LIST_SCOPE (list) = scope;
812 * gst_tag_list_get_scope:
813 * @list: a #GstTagList
815 * Gets the scope of @list.
817 * Returns: The scope of @list
820 gst_tag_list_get_scope (const GstTagList * list)
822 g_return_val_if_fail (GST_IS_TAG_LIST (list), GST_TAG_SCOPE_STREAM);
824 return GST_TAG_LIST_SCOPE (list);
828 * gst_tag_list_to_string:
829 * @list: a #GstTagList
831 * Serializes a tag list to a string.
833 * Returns: a newly-allocated string, or NULL in case of an error. The
834 * string must be freed with g_free() when no longer needed.
837 gst_tag_list_to_string (const GstTagList * list)
839 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
841 return gst_structure_to_string (GST_TAG_LIST_STRUCTURE (list));
845 * gst_tag_list_new_from_string:
846 * @str: a string created with gst_tag_list_to_string()
848 * Deserializes a tag list.
850 * Returns: a new #GstTagList, or NULL in case of an error.
853 gst_tag_list_new_from_string (const gchar * str)
855 GstTagList *tag_list;
858 g_return_val_if_fail (str != NULL, NULL);
859 g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
861 s = gst_structure_from_string (str, NULL);
865 tag_list = gst_tag_list_new_internal (s);
871 * gst_tag_list_n_tags:
872 * @list: A #GstTagList.
874 * Get the number of tags in @list.
876 * Returns: The number of tags in @list.
879 gst_tag_list_n_tags (const GstTagList * list)
881 g_return_val_if_fail (list != NULL, 0);
882 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
884 return gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list));
888 * gst_tag_list_nth_tag_name:
889 * @list: A #GstTagList.
892 * Get the name of the tag in @list at @index.
894 * Returns: The name of the tag at @index.
897 gst_tag_list_nth_tag_name (const GstTagList * list, guint index)
899 g_return_val_if_fail (list != NULL, 0);
900 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
902 return gst_structure_nth_field_name (GST_TAG_LIST_STRUCTURE (list), index);
906 * gst_tag_list_is_empty:
907 * @list: A #GstTagList.
909 * Checks if the given taglist is empty.
911 * Returns: TRUE if the taglist is empty, otherwise FALSE.
914 gst_tag_list_is_empty (const GstTagList * list)
916 g_return_val_if_fail (list != NULL, FALSE);
917 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
919 return (gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list)) == 0);
923 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
927 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
930 /* fields not equal: add some tolerance for doubles, otherwise bail out */
931 if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
934 d1 = g_value_get_double (value1);
935 d2 = g_value_get_double (value2);
937 /* This will only work for 'normal' values and values around 0,
938 * which should be good enough for our purposes here
939 * FIXME: maybe add this to gst_value_compare_double() ? */
940 return (fabs (d1 - d2) < 0.0000001);
944 * gst_tag_list_is_equal:
945 * @list1: a #GstTagList.
946 * @list2: a #GstTagList.
948 * Checks if the two given taglists are equal.
950 * Returns: TRUE if the taglists are equal, otherwise FALSE
953 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
955 const GstStructure *s1, *s2;
956 gint num_fields1, num_fields2, i;
958 g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
959 g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
961 /* we don't just use gst_structure_is_equal() here so we can add some
962 * tolerance for doubles, though maybe we should just add that to
963 * gst_value_compare_double() as well? */
964 s1 = GST_TAG_LIST_STRUCTURE (list1);
965 s2 = GST_TAG_LIST_STRUCTURE (list2);
967 num_fields1 = gst_structure_n_fields (s1);
968 num_fields2 = gst_structure_n_fields (s2);
970 if (num_fields1 != num_fields2)
973 for (i = 0; i < num_fields1; i++) {
974 const GValue *value1, *value2;
975 const gchar *tag_name;
977 tag_name = gst_structure_nth_field_name (s1, i);
978 value1 = gst_structure_get_value (s1, tag_name);
979 value2 = gst_structure_get_value (s2, tag_name);
984 if (!gst_tag_list_fields_equal (value1, value2))
994 GstTagMergeMode mode;
999 gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
1000 const gchar * tag, const GValue * value, GstTagInfo * info)
1002 GstStructure *list = GST_TAG_LIST_STRUCTURE (tag_list);
1003 const GValue *value2;
1007 info = gst_tag_lookup (tag);
1008 if (G_UNLIKELY (info == NULL)) {
1009 g_warning ("unknown tag '%s'", tag);
1014 if (G_UNLIKELY (!G_VALUE_HOLDS (value, info->type) &&
1015 !GST_VALUE_HOLDS_LIST (value))) {
1016 g_warning ("tag '%s' should hold value of type '%s', but value of "
1017 "type '%s' passed", info->nick, g_type_name (info->type),
1018 g_type_name (G_VALUE_TYPE (value)));
1022 tag_quark = info->name_quark;
1024 if (info->merge_func
1025 && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
1026 GValue dest = { 0, };
1029 case GST_TAG_MERGE_REPLACE_ALL:
1030 case GST_TAG_MERGE_REPLACE:
1031 gst_structure_id_set_value (list, tag_quark, value);
1033 case GST_TAG_MERGE_PREPEND:
1034 if (GST_VALUE_HOLDS_LIST (value2) && !GST_VALUE_HOLDS_LIST (value))
1035 gst_value_list_prepend_value ((GValue *) value2, value);
1037 gst_value_list_merge (&dest, value, value2);
1038 gst_structure_id_take_value (list, tag_quark, &dest);
1041 case GST_TAG_MERGE_APPEND:
1042 if (GST_VALUE_HOLDS_LIST (value2) && !GST_VALUE_HOLDS_LIST (value))
1043 gst_value_list_append_value ((GValue *) value2, value);
1045 gst_value_list_merge (&dest, value2, value);
1046 gst_structure_id_take_value (list, tag_quark, &dest);
1049 case GST_TAG_MERGE_KEEP:
1050 case GST_TAG_MERGE_KEEP_ALL:
1053 g_assert_not_reached ();
1058 case GST_TAG_MERGE_APPEND:
1059 case GST_TAG_MERGE_KEEP:
1060 if (gst_structure_id_get_value (list, tag_quark) != NULL)
1063 case GST_TAG_MERGE_REPLACE_ALL:
1064 case GST_TAG_MERGE_REPLACE:
1065 case GST_TAG_MERGE_PREPEND:
1066 gst_structure_id_set_value (list, tag_quark, value);
1068 case GST_TAG_MERGE_KEEP_ALL:
1071 g_assert_not_reached ();
1078 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
1081 GstTagCopyData *copy = (GstTagCopyData *) user_data;
1084 tag = g_quark_to_string (tag_quark);
1085 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
1091 * gst_tag_list_insert:
1092 * @into: list to merge into
1093 * @from: list to merge from
1094 * @mode: the mode to use
1096 * Inserts the tags of the @from list into the first list using the given mode.
1099 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
1100 GstTagMergeMode mode)
1102 GstTagCopyData data;
1104 g_return_if_fail (GST_IS_TAG_LIST (into));
1105 g_return_if_fail (gst_tag_list_is_writable (into));
1106 g_return_if_fail (GST_IS_TAG_LIST (from));
1107 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1111 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1112 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (into));
1114 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (from),
1115 gst_tag_list_copy_foreach, &data);
1119 * gst_tag_list_merge:
1120 * @list1: first list to merge
1121 * @list2: second list to merge
1122 * @mode: the mode to use
1124 * Merges the two given lists into a new list. If one of the lists is NULL, a
1125 * copy of the other is returned. If both lists are NULL, NULL is returned.
1127 * Free-function: gst_tag_list_unref
1129 * Returns: (transfer full): the new list
1132 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
1133 GstTagMergeMode mode)
1135 GstTagList *list1_cp;
1136 const GstTagList *list2_cp;
1138 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
1139 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
1140 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
1142 /* nothing to merge */
1143 if (!list1 && !list2) {
1147 /* create empty list, we need to do this to correctly handling merge modes */
1148 list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new_empty ();
1149 list2_cp = (list2) ? list2 : gst_tag_list_new_empty ();
1151 gst_tag_list_insert (list1_cp, list2_cp, mode);
1154 gst_tag_list_unref ((GstTagList *) list2_cp);
1160 * gst_tag_list_get_tag_size:
1162 * @tag: the tag to query
1164 * Checks how many value are stored in this tag list for the given tag.
1166 * Returns: The number of tags stored
1169 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1171 const GValue *value;
1173 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1175 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1178 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1181 return gst_value_list_get_size (value);
1186 * @list: list to set tags in
1187 * @mode: the mode to use
1189 * @...: NULL-terminated list of values to set
1191 * Sets the values for the given tags using the specified mode.
1194 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
1199 g_return_if_fail (GST_IS_TAG_LIST (list));
1200 g_return_if_fail (gst_tag_list_is_writable (list));
1201 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1202 g_return_if_fail (tag != NULL);
1204 va_start (args, tag);
1205 gst_tag_list_add_valist (list, mode, tag, args);
1210 * gst_tag_list_add_values:
1211 * @list: list to set tags in
1212 * @mode: the mode to use
1214 * @...: GValues to set
1216 * Sets the GValues for the given tags using the specified mode.
1219 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1220 const gchar * tag, ...)
1224 g_return_if_fail (GST_IS_TAG_LIST (list));
1225 g_return_if_fail (gst_tag_list_is_writable (list));
1226 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1227 g_return_if_fail (tag != NULL);
1229 va_start (args, tag);
1230 gst_tag_list_add_valist_values (list, mode, tag, args);
1235 * gst_tag_list_add_valist:
1236 * @list: list to set tags in
1237 * @mode: the mode to use
1239 * @var_args: tag / value pairs to set
1241 * Sets the values for the given tags using the specified mode.
1244 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1245 const gchar * tag, va_list var_args)
1248 gchar *error = NULL;
1250 g_return_if_fail (GST_IS_TAG_LIST (list));
1251 g_return_if_fail (gst_tag_list_is_writable (list));
1252 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1253 g_return_if_fail (tag != NULL);
1255 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1256 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1259 while (tag != NULL) {
1260 GValue value = { 0, };
1262 info = gst_tag_lookup (tag);
1263 if (G_UNLIKELY (info == NULL)) {
1264 g_warning ("unknown tag '%s'", tag);
1267 G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1269 g_warning ("%s: %s", G_STRLOC, error);
1271 /* we purposely leak the value here, it might not be
1272 * in a sane state if an error condition occoured
1276 /* Facilitate GstBuffer -> GstSample transition */
1277 if (G_UNLIKELY (info->type == GST_TYPE_SAMPLE &&
1278 !GST_IS_SAMPLE (value.data[0].v_pointer))) {
1279 g_warning ("Expected GstSample argument for tag '%s'", tag);
1281 gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1283 g_value_unset (&value);
1284 tag = va_arg (var_args, gchar *);
1289 * gst_tag_list_add_valist_values:
1290 * @list: list to set tags in
1291 * @mode: the mode to use
1293 * @var_args: tag / GValue pairs to set
1295 * Sets the GValues for the given tags using the specified mode.
1298 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1299 const gchar * tag, va_list var_args)
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 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1307 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1310 while (tag != NULL) {
1313 info = gst_tag_lookup (tag);
1314 if (G_UNLIKELY (info == NULL)) {
1315 g_warning ("unknown tag '%s'", tag);
1318 gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1320 tag = va_arg (var_args, gchar *);
1325 * gst_tag_list_add_value:
1326 * @list: list to set tags in
1327 * @mode: the mode to use
1329 * @value: GValue for this tag
1331 * Sets the GValue for a given tag using the specified mode.
1334 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1335 const gchar * tag, const GValue * value)
1337 g_return_if_fail (GST_IS_TAG_LIST (list));
1338 g_return_if_fail (gst_tag_list_is_writable (list));
1339 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1340 g_return_if_fail (tag != NULL);
1342 gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1346 * gst_tag_list_remove_tag:
1347 * @list: list to remove tag from
1348 * @tag: tag to remove
1350 * Removes the given tag from the taglist.
1353 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1355 g_return_if_fail (GST_IS_TAG_LIST (list));
1356 g_return_if_fail (tag != NULL);
1358 gst_structure_remove_field (GST_TAG_LIST_STRUCTURE (list), tag);
1363 GstTagForeachFunc func;
1364 const GstTagList *tag_list;
1370 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1373 TagForeachData *data = (TagForeachData *) user_data;
1375 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1380 * gst_tag_list_foreach:
1381 * @list: list to iterate over
1382 * @func: (scope call): function to be called for each tag
1383 * @user_data: (closure): user specified data
1385 * Calls the given function for each tag inside the tag list. Note that if there
1386 * is no tag, the function won't be called at all.
1389 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1392 TagForeachData data;
1394 g_return_if_fail (GST_IS_TAG_LIST (list));
1395 g_return_if_fail (func != NULL);
1398 data.tag_list = list;
1399 data.data = user_data;
1400 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (list),
1401 structure_foreach_wrapper, &data);
1405 * gst_tag_list_get_value_index:
1406 * @list: a #GstTagList
1407 * @tag: tag to read out
1408 * @index: number of entry to read out
1410 * Gets the value that is at the given index for the given tag in the given
1413 * Returns: (transfer none): The GValue for the specified entry or NULL if the
1414 * tag wasn't available or the tag doesn't have as many entries
1417 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1420 const GValue *value;
1422 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1423 g_return_val_if_fail (tag != NULL, NULL);
1425 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1429 if (GST_VALUE_HOLDS_LIST (value)) {
1430 if (index >= gst_value_list_get_size (value))
1432 return gst_value_list_get_value (value, index);
1441 * gst_tag_list_copy_value:
1442 * @dest: (out caller-allocates): uninitialized #GValue to copy into
1443 * @list: list to get the tag from
1444 * @tag: tag to read out
1446 * Copies the contents for the given tag into the value,
1447 * merging multiple values into one if multiple values are associated
1449 * You must g_value_unset() the value after use.
1451 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1455 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1460 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1461 g_return_val_if_fail (tag != NULL, FALSE);
1462 g_return_val_if_fail (dest != NULL, FALSE);
1463 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1465 src = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1469 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1470 GstTagInfo *info = gst_tag_lookup (tag);
1475 /* must be there or lists aren't allowed */
1476 g_assert (info->merge_func);
1477 info->merge_func (dest, src);
1479 g_value_init (dest, G_VALUE_TYPE (src));
1480 g_value_copy (src, dest);
1485 /* FIXME 0.11: this whole merge function business is overdesigned, and the
1486 * _get_foo() API is misleading as well - how many application developers will
1487 * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1488 * string with multiple comma-separated artists? _get_foo() should just be
1489 * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1490 * supplemented by a special _tag_list_get_string_merged() function if needed
1491 * (unless someone can actually think of real use cases where the merge
1492 * function is not 'use first' for non-strings and merge for strings) */
1494 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1496 #define TAG_MERGE_FUNCS(name,type,ret) \
1498 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
1501 GValue v = { 0, }; \
1503 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1504 g_return_val_if_fail (tag != NULL, FALSE); \
1505 g_return_val_if_fail (value != NULL, FALSE); \
1507 if (!gst_tag_list_copy_value (&v, list, tag)) \
1509 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
1510 g_value_unset (&v); \
1515 gst_tag_list_get_ ## name ## _index (const GstTagList *list, \
1517 guint index, type *value) \
1521 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1522 g_return_val_if_fail (tag != NULL, FALSE); \
1523 g_return_val_if_fail (value != NULL, FALSE); \
1525 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
1527 *value = COPY_FUNC (g_value_get_ ## name (v)); \
1531 #define COPY_FUNC /**/
1533 * gst_tag_list_get_boolean:
1534 * @list: a #GstTagList to get the tag from
1535 * @tag: tag to read out
1536 * @value: (out): location for the result
1538 * Copies the contents for the given tag into the value, merging multiple values
1539 * into one if multiple values are associated with the tag.
1541 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1545 * gst_tag_list_get_boolean_index:
1546 * @list: a #GstTagList to get the tag from
1547 * @tag: tag to read out
1548 * @index: number of entry to read out
1549 * @value: (out): location for the result
1551 * Gets the value that is at the given index for the given tag in the given
1554 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1557 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1559 * gst_tag_list_get_int:
1560 * @list: a #GstTagList to get the tag from
1561 * @tag: tag to read out
1562 * @value: (out): location for the result
1564 * Copies the contents for the given tag into the value, merging multiple values
1565 * into one if multiple values are associated with the tag.
1567 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1571 * gst_tag_list_get_int_index:
1572 * @list: a #GstTagList to get the tag from
1573 * @tag: tag to read out
1574 * @index: number of entry to read out
1575 * @value: (out): location for the result
1577 * Gets the value that is at the given index for the given tag in the given
1580 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1583 TAG_MERGE_FUNCS (int, gint, TRUE);
1585 * gst_tag_list_get_uint:
1586 * @list: a #GstTagList to get the tag from
1587 * @tag: tag to read out
1588 * @value: (out): location for the result
1590 * Copies the contents for the given tag into the value, merging multiple values
1591 * into one if multiple values are associated with the tag.
1593 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1597 * gst_tag_list_get_uint_index:
1598 * @list: a #GstTagList to get the tag from
1599 * @tag: tag to read out
1600 * @index: number of entry to read out
1601 * @value: (out): location for the result
1603 * Gets the value that is at the given index for the given tag in the given
1606 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1609 TAG_MERGE_FUNCS (uint, guint, TRUE);
1611 * gst_tag_list_get_int64_index:
1612 * @list: a #GstTagList to get the tag from
1613 * @tag: tag to read out
1614 * @index: number of entry to read out
1615 * @value: (out): location for the result
1617 * Gets the value that is at the given index for the given tag in the given
1620 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1623 TAG_MERGE_FUNCS (int64, gint64, TRUE);
1625 * gst_tag_list_get_uint64:
1626 * @list: a #GstTagList to get the tag from
1627 * @tag: tag to read out
1628 * @value: (out): location for the result
1630 * Copies the contents for the given tag into the value, merging multiple values
1631 * into one if multiple values are associated with the tag.
1633 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1637 * gst_tag_list_get_uint64_index:
1638 * @list: a #GstTagList to get the tag from
1639 * @tag: tag to read out
1640 * @index: number of entry to read out
1641 * @value: (out): location for the result
1643 * Gets the value that is at the given index for the given tag in the given
1646 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1649 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1651 * gst_tag_list_get_float:
1652 * @list: a #GstTagList to get the tag from
1653 * @tag: tag to read out
1654 * @value: (out): location for the result
1656 * Copies the contents for the given tag into the value, merging multiple values
1657 * into one if multiple values are associated with the tag.
1659 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1663 * gst_tag_list_get_float_index:
1664 * @list: a #GstTagList to get the tag from
1665 * @tag: tag to read out
1666 * @index: number of entry to read out
1667 * @value: (out): location for the result
1669 * Gets the value that is at the given index for the given tag in the given
1672 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1675 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1677 * gst_tag_list_get_double:
1678 * @list: a #GstTagList to get the tag from
1679 * @tag: tag to read out
1680 * @value: (out): location for the result
1682 * Copies the contents for the given tag into the value, merging multiple values
1683 * into one if multiple values are associated with the tag.
1685 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1689 * gst_tag_list_get_double_index:
1690 * @list: a #GstTagList to get the tag from
1691 * @tag: tag to read out
1692 * @index: number of entry to read out
1693 * @value: (out): location for the result
1695 * Gets the value that is at the given index for the given tag in the given
1698 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1701 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1703 * gst_tag_list_get_pointer:
1704 * @list: a #GstTagList to get the tag from
1705 * @tag: tag to read out
1706 * @value: (out) (transfer none): location for the result
1708 * Copies the contents for the given tag into the value, merging multiple values
1709 * into one if multiple values are associated with the tag.
1711 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1715 * gst_tag_list_get_pointer_index:
1716 * @list: a #GstTagList to get the tag from
1717 * @tag: tag to read out
1718 * @index: number of entry to read out
1719 * @value: (out) (transfer none): location for the result
1721 * Gets the value that is at the given index for the given tag in the given
1724 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1727 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1729 static inline gchar *
1730 _gst_strdup0 (const gchar * s)
1732 if (s == NULL || *s == '\0')
1735 return g_strdup (s);
1739 #define COPY_FUNC _gst_strdup0
1742 * gst_tag_list_get_string:
1743 * @list: a #GstTagList to get the tag from
1744 * @tag: tag to read out
1745 * @value: (out callee-allocates) (transfer full): location for the result
1747 * Copies the contents for the given tag into the value, possibly merging
1748 * multiple values into one if multiple values are associated with the tag.
1750 * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1751 * to retrieve the first string associated with this tag unmodified.
1753 * The resulting string in @value will be in UTF-8 encoding and should be
1754 * freed by the caller using g_free when no longer needed. The
1755 * returned string is also guaranteed to be non-NULL and non-empty.
1757 * Free-function: g_free
1759 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1763 * gst_tag_list_get_string_index:
1764 * @list: a #GstTagList to get the tag from
1765 * @tag: tag to read out
1766 * @index: number of entry to read out
1767 * @value: (out callee-allocates) (transfer full): location for the result
1769 * Gets the value that is at the given index for the given tag in the given
1772 * The resulting string in @value will be in UTF-8 encoding and should be
1773 * freed by the caller using g_free when no longer needed. The
1774 * returned string is also guaranteed to be non-NULL and non-empty.
1776 * Free-function: g_free
1778 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1781 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1784 *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have
1785 * _get (non-copy) and _dup (copy) for strings, seems more
1789 * gst_tag_list_peek_string_index:
1790 * @list: a #GstTagList to get the tag from
1791 * @tag: tag to read out
1792 * @index: number of entry to read out
1793 * @value: (out) (transfer none): location for the result
1795 * Peeks at the value that is at the given index for the given tag in the given
1798 * The resulting string in @value will be in UTF-8 encoding and doesn't need
1799 * to be freed by the caller. The returned string is also guaranteed to
1800 * be non-NULL and non-empty.
1802 * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the
1806 gst_tag_list_peek_string_index (const GstTagList * list,
1807 const gchar * tag, guint index, const gchar ** value)
1811 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1812 g_return_val_if_fail (tag != NULL, FALSE);
1813 g_return_val_if_fail (value != NULL, FALSE);
1815 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1817 *value = g_value_get_string (v);
1818 return *value != NULL && **value != '\0';
1822 * gst_tag_list_get_date:
1823 * @list: a #GstTagList to get the tag from
1824 * @tag: tag to read out
1825 * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1826 * variable to store the result into
1828 * Copies the first date for the given tag in the taglist into the variable
1829 * pointed to by @value. Free the date with g_date_free() when it is no longer
1832 * Free-function: g_date_free
1834 * Returns: TRUE, if a date was copied, FALSE if the tag didn't exist in the
1835 * given list or if it was #NULL.
1838 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1843 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1844 g_return_val_if_fail (tag != NULL, FALSE);
1845 g_return_val_if_fail (value != NULL, FALSE);
1847 if (!gst_tag_list_copy_value (&v, list, tag))
1849 *value = (GDate *) g_value_dup_boxed (&v);
1851 return (*value != NULL);
1855 * gst_tag_list_get_date_index:
1856 * @list: a #GstTagList to get the tag from
1857 * @tag: tag to read out
1858 * @index: number of entry to read out
1859 * @value: (out callee-allocates) (transfer full): location for the result
1861 * Gets the date that is at the given index for the given tag in the given
1862 * list and copies it into the variable pointed to by @value. Free the date
1863 * with g_date_free() when it is no longer needed.
1865 * Free-function: g_date_free
1867 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1868 * given list or if it was #NULL.
1871 gst_tag_list_get_date_index (const GstTagList * list,
1872 const gchar * tag, guint index, GDate ** value)
1876 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1877 g_return_val_if_fail (tag != NULL, FALSE);
1878 g_return_val_if_fail (value != NULL, FALSE);
1880 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1882 *value = (GDate *) g_value_dup_boxed (v);
1883 return (*value != NULL);
1887 * gst_tag_list_get_date_time:
1888 * @list: a #GstTagList to get the tag from
1889 * @tag: tag to read out
1890 * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1891 * pointer variable to store the result into
1893 * Copies the first datetime for the given tag in the taglist into the variable
1894 * pointed to by @value. Unref the date with gst_date_time_unref() when
1895 * it is no longer needed.
1897 * Free-function: gst_date_time_unref
1899 * Returns: TRUE, if a datetime was copied, FALSE if the tag didn't exist in
1900 * thegiven list or if it was #NULL.
1903 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1904 GstDateTime ** value)
1908 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1909 g_return_val_if_fail (tag != NULL, FALSE);
1910 g_return_val_if_fail (value != NULL, FALSE);
1912 if (!gst_tag_list_copy_value (&v, list, tag))
1915 g_return_val_if_fail (GST_VALUE_HOLDS_DATE_TIME (&v), FALSE);
1917 *value = (GstDateTime *) g_value_dup_boxed (&v);
1919 return (*value != NULL);
1923 * gst_tag_list_get_date_time_index:
1924 * @list: a #GstTagList to get the tag from
1925 * @tag: tag to read out
1926 * @index: number of entry to read out
1927 * @value: (out callee-allocates) (transfer full): location for the result
1929 * Gets the datetime that is at the given index for the given tag in the given
1930 * list and copies it into the variable pointed to by @value. Unref the datetime
1931 * with gst_date_time_unref() when it is no longer needed.
1933 * Free-function: gst_date_time_unref
1935 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1936 * given list or if it was #NULL.
1939 gst_tag_list_get_date_time_index (const GstTagList * list,
1940 const gchar * tag, guint index, GstDateTime ** value)
1944 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1945 g_return_val_if_fail (tag != NULL, FALSE);
1946 g_return_val_if_fail (value != NULL, FALSE);
1948 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1950 *value = (GstDateTime *) g_value_dup_boxed (v);
1951 return (*value != NULL);
1955 * gst_tag_list_get_sample:
1956 * @list: a #GstTagList to get the tag from
1957 * @tag: tag to read out
1958 * @sample: (out callee-allocates) (transfer full): address of a GstSample
1959 * pointer variable to store the result into
1961 * Copies the first sample for the given tag in the taglist into the variable
1962 * pointed to by @sample. Free the sample with gst_sample_unref() when it is
1963 * no longer needed. You can retrieve the buffer from the sample using
1964 * gst_sample_get_buffer() and the associated caps (if any) with
1965 * gst_sample_get_caps().
1967 * Free-function: gst_sample_unref
1969 * Returns: TRUE, if a sample was returned, FALSE if the tag didn't exist in
1970 * the given list or if it was #NULL.
1973 gst_tag_list_get_sample (const GstTagList * list, const gchar * tag,
1974 GstSample ** sample)
1978 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1979 g_return_val_if_fail (tag != NULL, FALSE);
1980 g_return_val_if_fail (sample != NULL, FALSE);
1982 if (!gst_tag_list_copy_value (&v, list, tag))
1984 *sample = g_value_dup_boxed (&v);
1986 return (*sample != NULL);
1990 * gst_tag_list_get_sample_index:
1991 * @list: a #GstTagList to get the tag from
1992 * @tag: tag to read out
1993 * @index: number of entry to read out
1994 * @sample: (out callee-allocates) (transfer full): address of a GstSample
1995 * pointer variable to store the result into
1997 * Gets the sample that is at the given index for the given tag in the given
1998 * list and copies it into the variable pointed to by @smple. Free the sample
1999 * with gst_sample_unref() when it is no longer needed. You can retrieve the
2000 * buffer from the sample using gst_sample_get_buffer() and the associated
2001 * caps (if any) with gst_sample_get_caps().
2003 * Free-function: gst_sample_unref
2005 * Returns: TRUE, if a sample was copied, FALSE if the tag didn't exist in the
2006 * given list or if it was #NULL.
2009 gst_tag_list_get_sample_index (const GstTagList * list,
2010 const gchar * tag, guint index, GstSample ** sample)
2014 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
2015 g_return_val_if_fail (tag != NULL, FALSE);
2016 g_return_val_if_fail (sample != NULL, FALSE);
2018 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
2020 *sample = g_value_dup_boxed (v);
2021 return (*sample != NULL);