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: 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: 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;
857 g_return_val_if_fail (str != NULL, NULL);
858 g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
860 tag_list = gst_tag_list_new_internal (gst_structure_from_string (str, NULL));
865 * gst_tag_list_n_tags:
866 * @list: A #GstTagList.
868 * Get the number of tags in @list.
870 * Returns: The number of tags in @list.
873 gst_tag_list_n_tags (const GstTagList * list)
875 g_return_val_if_fail (list != NULL, 0);
876 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
878 return gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list));
882 * gst_tag_list_nth_tag_name:
883 * @list: A #GstTagList.
886 * Get the name of the tag in @list at @index.
888 * Returns: The name of the tag at @index.
891 gst_tag_list_nth_tag_name (const GstTagList * list, guint index)
893 g_return_val_if_fail (list != NULL, 0);
894 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
896 return gst_structure_nth_field_name (GST_TAG_LIST_STRUCTURE (list), index);
900 * gst_tag_list_is_empty:
901 * @list: A #GstTagList.
903 * Checks if the given taglist is empty.
905 * Returns: TRUE if the taglist is empty, otherwise FALSE.
908 gst_tag_list_is_empty (const GstTagList * list)
910 g_return_val_if_fail (list != NULL, FALSE);
911 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
913 return (gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list)) == 0);
917 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
921 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
924 /* fields not equal: add some tolerance for doubles, otherwise bail out */
925 if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
928 d1 = g_value_get_double (value1);
929 d2 = g_value_get_double (value2);
931 /* This will only work for 'normal' values and values around 0,
932 * which should be good enough for our purposes here
933 * FIXME: maybe add this to gst_value_compare_double() ? */
934 return (fabs (d1 - d2) < 0.0000001);
938 * gst_tag_list_is_equal:
939 * @list1: a #GstTagList.
940 * @list2: a #GstTagList.
942 * Checks if the two given taglists are equal.
944 * Returns: TRUE if the taglists are equal, otherwise FALSE
947 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
949 const GstStructure *s1, *s2;
950 gint num_fields1, num_fields2, i;
952 g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
953 g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
955 /* we don't just use gst_structure_is_equal() here so we can add some
956 * tolerance for doubles, though maybe we should just add that to
957 * gst_value_compare_double() as well? */
958 s1 = GST_TAG_LIST_STRUCTURE (list1);
959 s2 = GST_TAG_LIST_STRUCTURE (list2);
961 num_fields1 = gst_structure_n_fields (s1);
962 num_fields2 = gst_structure_n_fields (s2);
964 if (num_fields1 != num_fields2)
967 for (i = 0; i < num_fields1; i++) {
968 const GValue *value1, *value2;
969 const gchar *tag_name;
971 tag_name = gst_structure_nth_field_name (s1, i);
972 value1 = gst_structure_get_value (s1, tag_name);
973 value2 = gst_structure_get_value (s2, tag_name);
978 if (!gst_tag_list_fields_equal (value1, value2))
988 GstTagMergeMode mode;
993 gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
994 const gchar * tag, const GValue * value, GstTagInfo * info)
996 GstStructure *list = GST_TAG_LIST_STRUCTURE (tag_list);
997 const GValue *value2;
1001 info = gst_tag_lookup (tag);
1002 if (G_UNLIKELY (info == NULL)) {
1003 g_warning ("unknown tag '%s'", tag);
1008 if (G_UNLIKELY (!G_VALUE_HOLDS (value, info->type) &&
1009 !GST_VALUE_HOLDS_LIST (value))) {
1010 g_warning ("tag '%s' should hold value of type '%s', but value of "
1011 "type '%s' passed", info->nick, g_type_name (info->type),
1012 g_type_name (G_VALUE_TYPE (value)));
1016 tag_quark = info->name_quark;
1018 if (info->merge_func
1019 && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
1020 GValue dest = { 0, };
1023 case GST_TAG_MERGE_REPLACE_ALL:
1024 case GST_TAG_MERGE_REPLACE:
1025 gst_structure_id_set_value (list, tag_quark, value);
1027 case GST_TAG_MERGE_PREPEND:
1028 gst_value_list_merge (&dest, value, value2);
1029 gst_structure_id_take_value (list, tag_quark, &dest);
1031 case GST_TAG_MERGE_APPEND:
1032 gst_value_list_merge (&dest, value2, value);
1033 gst_structure_id_take_value (list, tag_quark, &dest);
1035 case GST_TAG_MERGE_KEEP:
1036 case GST_TAG_MERGE_KEEP_ALL:
1039 g_assert_not_reached ();
1044 case GST_TAG_MERGE_APPEND:
1045 case GST_TAG_MERGE_KEEP:
1046 if (gst_structure_id_get_value (list, tag_quark) != NULL)
1049 case GST_TAG_MERGE_REPLACE_ALL:
1050 case GST_TAG_MERGE_REPLACE:
1051 case GST_TAG_MERGE_PREPEND:
1052 gst_structure_id_set_value (list, tag_quark, value);
1054 case GST_TAG_MERGE_KEEP_ALL:
1057 g_assert_not_reached ();
1064 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
1067 GstTagCopyData *copy = (GstTagCopyData *) user_data;
1070 tag = g_quark_to_string (tag_quark);
1071 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
1077 * gst_tag_list_insert:
1078 * @into: list to merge into
1079 * @from: list to merge from
1080 * @mode: the mode to use
1082 * Inserts the tags of the @from list into the first list using the given mode.
1085 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
1086 GstTagMergeMode mode)
1088 GstTagCopyData data;
1090 g_return_if_fail (GST_IS_TAG_LIST (into));
1091 g_return_if_fail (gst_tag_list_is_writable (into));
1092 g_return_if_fail (GST_IS_TAG_LIST (from));
1093 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1097 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1098 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (into));
1100 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (from),
1101 gst_tag_list_copy_foreach, &data);
1105 * gst_tag_list_merge:
1106 * @list1: first list to merge
1107 * @list2: second list to merge
1108 * @mode: the mode to use
1110 * Merges the two given lists into a new list. If one of the lists is NULL, a
1111 * copy of the other is returned. If both lists are NULL, NULL is returned.
1113 * Free-function: gst_tag_list_unref
1115 * Returns: (transfer full): the new list
1118 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
1119 GstTagMergeMode mode)
1121 GstTagList *list1_cp;
1122 const GstTagList *list2_cp;
1124 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
1125 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
1126 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
1128 /* nothing to merge */
1129 if (!list1 && !list2) {
1133 /* create empty list, we need to do this to correctly handling merge modes */
1134 list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new_empty ();
1135 list2_cp = (list2) ? list2 : gst_tag_list_new_empty ();
1137 gst_tag_list_insert (list1_cp, list2_cp, mode);
1140 gst_tag_list_unref ((GstTagList *) list2_cp);
1146 * gst_tag_list_get_tag_size:
1148 * @tag: the tag to query
1150 * Checks how many value are stored in this tag list for the given tag.
1152 * Returns: The number of tags stored
1155 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1157 const GValue *value;
1159 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1161 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1164 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1167 return gst_value_list_get_size (value);
1172 * @list: list to set tags in
1173 * @mode: the mode to use
1175 * @...: NULL-terminated list of values to set
1177 * Sets the values for the given tags using the specified mode.
1180 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, const gchar * tag,
1185 g_return_if_fail (GST_IS_TAG_LIST (list));
1186 g_return_if_fail (gst_tag_list_is_writable (list));
1187 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1188 g_return_if_fail (tag != NULL);
1190 va_start (args, tag);
1191 gst_tag_list_add_valist (list, mode, tag, args);
1196 * gst_tag_list_add_values:
1197 * @list: list to set tags in
1198 * @mode: the mode to use
1200 * @...: GValues to set
1202 * Sets the GValues for the given tags using the specified mode.
1205 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1206 const gchar * tag, ...)
1210 g_return_if_fail (GST_IS_TAG_LIST (list));
1211 g_return_if_fail (gst_tag_list_is_writable (list));
1212 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1213 g_return_if_fail (tag != NULL);
1215 va_start (args, tag);
1216 gst_tag_list_add_valist_values (list, mode, tag, args);
1221 * gst_tag_list_add_valist:
1222 * @list: list to set tags in
1223 * @mode: the mode to use
1225 * @var_args: tag / value pairs to set
1227 * Sets the values for the given tags using the specified mode.
1230 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1231 const gchar * tag, va_list var_args)
1234 gchar *error = NULL;
1236 g_return_if_fail (GST_IS_TAG_LIST (list));
1237 g_return_if_fail (gst_tag_list_is_writable (list));
1238 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1239 g_return_if_fail (tag != NULL);
1241 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1242 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1245 while (tag != NULL) {
1246 GValue value = { 0, };
1248 info = gst_tag_lookup (tag);
1249 if (G_UNLIKELY (info == NULL)) {
1250 g_warning ("unknown tag '%s'", tag);
1253 G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1255 g_warning ("%s: %s", G_STRLOC, error);
1257 /* we purposely leak the value here, it might not be
1258 * in a sane state if an error condition occoured
1262 /* Facilitate GstBuffer -> GstSample transition */
1263 if (G_UNLIKELY (info->type == GST_TYPE_SAMPLE &&
1264 !GST_IS_SAMPLE (value.data[0].v_pointer))) {
1265 g_warning ("Expected GstSample argument for tag '%s'", tag);
1267 gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1269 g_value_unset (&value);
1270 tag = va_arg (var_args, gchar *);
1275 * gst_tag_list_add_valist_values:
1276 * @list: list to set tags in
1277 * @mode: the mode to use
1279 * @var_args: tag / GValue pairs to set
1281 * Sets the GValues for the given tags using the specified mode.
1284 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1285 const gchar * tag, va_list var_args)
1287 g_return_if_fail (GST_IS_TAG_LIST (list));
1288 g_return_if_fail (gst_tag_list_is_writable (list));
1289 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1290 g_return_if_fail (tag != NULL);
1292 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1293 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1296 while (tag != NULL) {
1299 info = gst_tag_lookup (tag);
1300 if (G_UNLIKELY (info == NULL)) {
1301 g_warning ("unknown tag '%s'", tag);
1304 gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1306 tag = va_arg (var_args, gchar *);
1311 * gst_tag_list_add_value:
1312 * @list: list to set tags in
1313 * @mode: the mode to use
1315 * @value: GValue for this tag
1317 * Sets the GValue for a given tag using the specified mode.
1320 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1321 const gchar * tag, const GValue * value)
1323 g_return_if_fail (GST_IS_TAG_LIST (list));
1324 g_return_if_fail (gst_tag_list_is_writable (list));
1325 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1326 g_return_if_fail (tag != NULL);
1328 gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1332 * gst_tag_list_remove_tag:
1333 * @list: list to remove tag from
1334 * @tag: tag to remove
1336 * Removes the given tag from the taglist.
1339 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1341 g_return_if_fail (GST_IS_TAG_LIST (list));
1342 g_return_if_fail (tag != NULL);
1344 gst_structure_remove_field (GST_TAG_LIST_STRUCTURE (list), tag);
1349 GstTagForeachFunc func;
1350 const GstTagList *tag_list;
1356 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1359 TagForeachData *data = (TagForeachData *) user_data;
1361 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1366 * gst_tag_list_foreach:
1367 * @list: list to iterate over
1368 * @func: (scope call): function to be called for each tag
1369 * @user_data: (closure): user specified data
1371 * Calls the given function for each tag inside the tag list. Note that if there
1372 * is no tag, the function won't be called at all.
1375 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1378 TagForeachData data;
1380 g_return_if_fail (GST_IS_TAG_LIST (list));
1381 g_return_if_fail (func != NULL);
1384 data.tag_list = list;
1385 data.data = user_data;
1386 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (list),
1387 structure_foreach_wrapper, &data);
1391 * gst_tag_list_get_value_index:
1392 * @list: a #GstTagList
1393 * @tag: tag to read out
1394 * @index: number of entry to read out
1396 * Gets the value that is at the given index for the given tag in the given
1399 * Returns: (transfer none): The GValue for the specified entry or NULL if the
1400 * tag wasn't available or the tag doesn't have as many entries
1403 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1406 const GValue *value;
1408 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1409 g_return_val_if_fail (tag != NULL, NULL);
1411 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1415 if (GST_VALUE_HOLDS_LIST (value)) {
1416 if (index >= gst_value_list_get_size (value))
1418 return gst_value_list_get_value (value, index);
1427 * gst_tag_list_copy_value:
1428 * @dest: (out caller-allocates): uninitialized #GValue to copy into
1429 * @list: list to get the tag from
1430 * @tag: tag to read out
1432 * Copies the contents for the given tag into the value,
1433 * merging multiple values into one if multiple values are associated
1435 * You must g_value_unset() the value after use.
1437 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1441 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1446 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1447 g_return_val_if_fail (tag != NULL, FALSE);
1448 g_return_val_if_fail (dest != NULL, FALSE);
1449 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1451 src = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1455 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1456 GstTagInfo *info = gst_tag_lookup (tag);
1461 /* must be there or lists aren't allowed */
1462 g_assert (info->merge_func);
1463 info->merge_func (dest, src);
1465 g_value_init (dest, G_VALUE_TYPE (src));
1466 g_value_copy (src, dest);
1471 /* FIXME 0.11: this whole merge function business is overdesigned, and the
1472 * _get_foo() API is misleading as well - how many application developers will
1473 * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1474 * string with multiple comma-separated artists? _get_foo() should just be
1475 * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1476 * supplemented by a special _tag_list_get_string_merged() function if needed
1477 * (unless someone can actually think of real use cases where the merge
1478 * function is not 'use first' for non-strings and merge for strings) */
1480 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1482 #define TAG_MERGE_FUNCS(name,type,ret) \
1484 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
1487 GValue v = { 0, }; \
1489 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1490 g_return_val_if_fail (tag != NULL, FALSE); \
1491 g_return_val_if_fail (value != NULL, FALSE); \
1493 if (!gst_tag_list_copy_value (&v, list, tag)) \
1495 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
1496 g_value_unset (&v); \
1501 gst_tag_list_get_ ## name ## _index (const GstTagList *list, \
1503 guint index, type *value) \
1507 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1508 g_return_val_if_fail (tag != NULL, FALSE); \
1509 g_return_val_if_fail (value != NULL, FALSE); \
1511 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
1513 *value = COPY_FUNC (g_value_get_ ## name (v)); \
1517 #define COPY_FUNC /**/
1519 * gst_tag_list_get_boolean:
1520 * @list: a #GstTagList to get the tag from
1521 * @tag: tag to read out
1522 * @value: (out): location for the result
1524 * Copies the contents for the given tag into the value, merging multiple values
1525 * into one if multiple values are associated with the tag.
1527 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1531 * gst_tag_list_get_boolean_index:
1532 * @list: a #GstTagList to get the tag from
1533 * @tag: tag to read out
1534 * @index: number of entry to read out
1535 * @value: (out): location for the result
1537 * Gets the value that is at the given index for the given tag in the given
1540 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1543 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1545 * gst_tag_list_get_int:
1546 * @list: a #GstTagList to get the tag from
1547 * @tag: tag to read out
1548 * @value: (out): location for the result
1550 * Copies the contents for the given tag into the value, merging multiple values
1551 * into one if multiple values are associated with the tag.
1553 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1557 * gst_tag_list_get_int_index:
1558 * @list: a #GstTagList to get the tag from
1559 * @tag: tag to read out
1560 * @index: number of entry to read out
1561 * @value: (out): location for the result
1563 * Gets the value that is at the given index for the given tag in the given
1566 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1569 TAG_MERGE_FUNCS (int, gint, TRUE);
1571 * gst_tag_list_get_uint:
1572 * @list: a #GstTagList to get the tag from
1573 * @tag: tag to read out
1574 * @value: (out): location for the result
1576 * Copies the contents for the given tag into the value, merging multiple values
1577 * into one if multiple values are associated with the tag.
1579 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1583 * gst_tag_list_get_uint_index:
1584 * @list: a #GstTagList to get the tag from
1585 * @tag: tag to read out
1586 * @index: number of entry to read out
1587 * @value: (out): location for the result
1589 * Gets the value that is at the given index for the given tag in the given
1592 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1595 TAG_MERGE_FUNCS (uint, guint, TRUE);
1597 * gst_tag_list_get_int64_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 (int64, gint64, TRUE);
1611 * gst_tag_list_get_uint64:
1612 * @list: a #GstTagList to get the tag from
1613 * @tag: tag to read out
1614 * @value: (out): location for the result
1616 * Copies the contents for the given tag into the value, merging multiple values
1617 * into one if multiple values are associated with the tag.
1619 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1623 * gst_tag_list_get_uint64_index:
1624 * @list: a #GstTagList to get the tag from
1625 * @tag: tag to read out
1626 * @index: number of entry to read out
1627 * @value: (out): location for the result
1629 * Gets the value that is at the given index for the given tag in the given
1632 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1635 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1637 * gst_tag_list_get_float:
1638 * @list: a #GstTagList to get the tag from
1639 * @tag: tag to read out
1640 * @value: (out): location for the result
1642 * Copies the contents for the given tag into the value, merging multiple values
1643 * into one if multiple values are associated with the tag.
1645 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1649 * gst_tag_list_get_float_index:
1650 * @list: a #GstTagList to get the tag from
1651 * @tag: tag to read out
1652 * @index: number of entry to read out
1653 * @value: (out): location for the result
1655 * Gets the value that is at the given index for the given tag in the given
1658 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1661 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1663 * gst_tag_list_get_double:
1664 * @list: a #GstTagList to get the tag from
1665 * @tag: tag to read out
1666 * @value: (out): location for the result
1668 * Copies the contents for the given tag into the value, merging multiple values
1669 * into one if multiple values are associated with the tag.
1671 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1675 * gst_tag_list_get_double_index:
1676 * @list: a #GstTagList to get the tag from
1677 * @tag: tag to read out
1678 * @index: number of entry to read out
1679 * @value: (out): location for the result
1681 * Gets the value that is at the given index for the given tag in the given
1684 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1687 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1689 * gst_tag_list_get_pointer:
1690 * @list: a #GstTagList to get the tag from
1691 * @tag: tag to read out
1692 * @value: (out) (transfer none): location for the result
1694 * Copies the contents for the given tag into the value, merging multiple values
1695 * into one if multiple values are associated with the tag.
1697 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1701 * gst_tag_list_get_pointer_index:
1702 * @list: a #GstTagList to get the tag from
1703 * @tag: tag to read out
1704 * @index: number of entry to read out
1705 * @value: (out) (transfer none): location for the result
1707 * Gets the value that is at the given index for the given tag in the given
1710 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1713 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1715 static inline gchar *
1716 _gst_strdup0 (const gchar * s)
1718 if (s == NULL || *s == '\0')
1721 return g_strdup (s);
1725 #define COPY_FUNC _gst_strdup0
1728 * gst_tag_list_get_string:
1729 * @list: a #GstTagList to get the tag from
1730 * @tag: tag to read out
1731 * @value: (out callee-allocates) (transfer full): location for the result
1733 * Copies the contents for the given tag into the value, possibly merging
1734 * multiple values into one if multiple values are associated with the tag.
1736 * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1737 * to retrieve the first string associated with this tag unmodified.
1739 * The resulting string in @value will be in UTF-8 encoding and should be
1740 * freed by the caller using g_free when no longer needed. The
1741 * returned string is also guaranteed to be non-NULL and non-empty.
1743 * Free-function: g_free
1745 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1749 * gst_tag_list_get_string_index:
1750 * @list: a #GstTagList to get the tag from
1751 * @tag: tag to read out
1752 * @index: number of entry to read out
1753 * @value: (out callee-allocates) (transfer full): location for the result
1755 * Gets the value that is at the given index for the given tag in the given
1758 * The resulting string in @value will be in UTF-8 encoding and should be
1759 * freed by the caller using g_free when no longer needed. The
1760 * returned string is also guaranteed to be non-NULL and non-empty.
1762 * Free-function: g_free
1764 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1767 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1770 *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have
1771 * _get (non-copy) and _dup (copy) for strings, seems more
1775 * gst_tag_list_peek_string_index:
1776 * @list: a #GstTagList to get the tag from
1777 * @tag: tag to read out
1778 * @index: number of entry to read out
1779 * @value: (out) (transfer none): location for the result
1781 * Peeks at the value that is at the given index for the given tag in the given
1784 * The resulting string in @value will be in UTF-8 encoding and doesn't need
1785 * to be freed by the caller. The returned string is also guaranteed to
1786 * be non-NULL and non-empty.
1788 * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the
1792 gst_tag_list_peek_string_index (const GstTagList * list,
1793 const gchar * tag, guint index, const gchar ** value)
1797 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1798 g_return_val_if_fail (tag != NULL, FALSE);
1799 g_return_val_if_fail (value != NULL, FALSE);
1801 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1803 *value = g_value_get_string (v);
1804 return *value != NULL && **value != '\0';
1808 * gst_tag_list_get_date:
1809 * @list: a #GstTagList to get the tag from
1810 * @tag: tag to read out
1811 * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1812 * variable to store the result into
1814 * Copies the first date for the given tag in the taglist into the variable
1815 * pointed to by @value. Free the date with g_date_free() when it is no longer
1818 * Free-function: g_date_free
1820 * Returns: TRUE, if a date was copied, FALSE if the tag didn't exist in the
1821 * given list or if it was #NULL.
1824 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1829 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1830 g_return_val_if_fail (tag != NULL, FALSE);
1831 g_return_val_if_fail (value != NULL, FALSE);
1833 if (!gst_tag_list_copy_value (&v, list, tag))
1835 *value = (GDate *) g_value_dup_boxed (&v);
1837 return (*value != NULL);
1841 * gst_tag_list_get_date_index:
1842 * @list: a #GstTagList to get the tag from
1843 * @tag: tag to read out
1844 * @index: number of entry to read out
1845 * @value: (out callee-allocates) (transfer full): location for the result
1847 * Gets the date that is at the given index for the given tag in the given
1848 * list and copies it into the variable pointed to by @value. Free the date
1849 * with g_date_free() when it is no longer needed.
1851 * Free-function: g_date_free
1853 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1854 * given list or if it was #NULL.
1857 gst_tag_list_get_date_index (const GstTagList * list,
1858 const gchar * tag, guint index, GDate ** value)
1862 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1863 g_return_val_if_fail (tag != NULL, FALSE);
1864 g_return_val_if_fail (value != NULL, FALSE);
1866 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1868 *value = (GDate *) g_value_dup_boxed (v);
1869 return (*value != NULL);
1873 * gst_tag_list_get_date_time:
1874 * @list: a #GstTagList to get the tag from
1875 * @tag: tag to read out
1876 * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1877 * pointer variable to store the result into
1879 * Copies the first datetime for the given tag in the taglist into the variable
1880 * pointed to by @value. Unref the date with gst_date_time_unref() when
1881 * it is no longer needed.
1883 * Free-function: gst_date_time_unref
1885 * Returns: TRUE, if a datetime was copied, FALSE if the tag didn't exist in
1886 * thegiven list or if it was #NULL.
1889 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1890 GstDateTime ** value)
1894 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1895 g_return_val_if_fail (tag != NULL, FALSE);
1896 g_return_val_if_fail (value != NULL, FALSE);
1898 if (!gst_tag_list_copy_value (&v, list, tag))
1901 g_return_val_if_fail (GST_VALUE_HOLDS_DATE_TIME (&v), FALSE);
1903 *value = (GstDateTime *) g_value_dup_boxed (&v);
1905 return (*value != NULL);
1909 * gst_tag_list_get_date_time_index:
1910 * @list: a #GstTagList to get the tag from
1911 * @tag: tag to read out
1912 * @index: number of entry to read out
1913 * @value: (out callee-allocates) (transfer full): location for the result
1915 * Gets the datetime that is at the given index for the given tag in the given
1916 * list and copies it into the variable pointed to by @value. Unref the datetime
1917 * with gst_date_time_unref() when it is no longer needed.
1919 * Free-function: gst_date_time_unref
1921 * Returns: TRUE, if a value was copied, FALSE if the tag didn't exist in the
1922 * given list or if it was #NULL.
1925 gst_tag_list_get_date_time_index (const GstTagList * list,
1926 const gchar * tag, guint index, GstDateTime ** value)
1930 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1931 g_return_val_if_fail (tag != NULL, FALSE);
1932 g_return_val_if_fail (value != NULL, FALSE);
1934 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1936 *value = (GstDateTime *) g_value_dup_boxed (v);
1937 return (*value != NULL);
1941 * gst_tag_list_get_sample:
1942 * @list: a #GstTagList to get the tag from
1943 * @tag: tag to read out
1944 * @sample: (out callee-allocates) (transfer full): address of a GstSample
1945 * pointer variable to store the result into
1947 * Copies the first sample for the given tag in the taglist into the variable
1948 * pointed to by @sample. Free the sample with gst_sample_unref() when it is
1949 * no longer needed. You can retrieve the buffer from the sample using
1950 * gst_sample_get_buffer() and the associated caps (if any) with
1951 * gst_sample_get_caps().
1953 * Free-function: gst_sample_unref
1955 * Returns: TRUE, if a sample was returned, FALSE if the tag didn't exist in
1956 * the given list or if it was #NULL.
1959 gst_tag_list_get_sample (const GstTagList * list, const gchar * tag,
1960 GstSample ** sample)
1964 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1965 g_return_val_if_fail (tag != NULL, FALSE);
1966 g_return_val_if_fail (sample != NULL, FALSE);
1968 if (!gst_tag_list_copy_value (&v, list, tag))
1970 *sample = g_value_dup_boxed (&v);
1972 return (*sample != NULL);
1976 * gst_tag_list_get_sample_index:
1977 * @list: a #GstTagList to get the tag from
1978 * @tag: tag to read out
1979 * @index: number of entry to read out
1980 * @sample: (out callee-allocates) (transfer full): address of a GstSample
1981 * pointer variable to store the result into
1983 * Gets the sample that is at the given index for the given tag in the given
1984 * list and copies it into the variable pointed to by @smple. Free the sample
1985 * with gst_sample_unref() when it is no longer needed. You can retrieve the
1986 * buffer from the sample using gst_sample_get_buffer() and the associated
1987 * caps (if any) with gst_sample_get_caps().
1989 * Free-function: gst_sample_unref
1991 * Returns: TRUE, if a sample was copied, FALSE if the tag didn't exist in the
1992 * given list or if it was #NULL.
1995 gst_tag_list_get_sample_index (const GstTagList * list,
1996 const gchar * tag, guint index, GstSample ** sample)
2000 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
2001 g_return_val_if_fail (tag != NULL, FALSE);
2002 g_return_val_if_fail (sample != NULL, FALSE);
2004 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
2006 *sample = g_value_dup_boxed (v);
2007 return (*sample != NULL);