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 in structures must be ASCII or UTF-8 encoded. Other encodings are
29 * not allowed. Strings must not be empty or %NULL.
36 #include "gst_private.h"
37 #include "math-compat.h"
38 #include "gst-i18n-lib.h"
39 #include "gsttaglist.h"
42 #include "gstbuffer.h"
44 #include "gststructure.h"
46 #include <gobject/gvaluecollector.h>
49 /* FIXME: add category for tags */
50 #define GST_CAT_TAGS GST_CAT_DEFAULT
52 #define GST_TAG_IS_VALID(tag) (gst_tag_get_info (tag) != NULL)
54 typedef struct _GstTagListImpl
58 GstStructure *structure;
62 #define GST_TAG_LIST_STRUCTURE(taglist) ((GstTagListImpl*)(taglist))->structure
63 #define GST_TAG_LIST_SCOPE(taglist) ((GstTagListImpl*)(taglist))->scope
67 GType type; /* type the data is in */
69 const gchar *nick; /* translated short description */
70 const gchar *blurb; /* translated long description */
72 GstTagMergeFunc merge_func; /* functions to merge the values */
73 GstTagFlag flag; /* type of tag */
74 GQuark name_quark; /* quark for the name */
78 #define g_value_get_char g_value_get_schar
80 static GMutex __tag_mutex;
81 #define TAG_LOCK g_mutex_lock (&__tag_mutex)
82 #define TAG_UNLOCK g_mutex_unlock (&__tag_mutex)
84 /* tags hash table: maps tag name string => GstTagInfo */
85 static GHashTable *__tags;
87 GType _gst_tag_list_type = 0;
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 _gst_tag_list_type = gst_tag_list_get_type ();
104 __tags = g_hash_table_new (g_str_hash, g_str_equal);
105 gst_tag_register_static (GST_TAG_TITLE, GST_TAG_FLAG_META,
107 _("title"), _("commonly used title"), gst_tag_merge_strings_with_comma);
108 gst_tag_register_static (GST_TAG_TITLE_SORTNAME, GST_TAG_FLAG_META,
110 _("title sortname"), _("commonly used title for sorting purposes"), NULL);
111 gst_tag_register_static (GST_TAG_ARTIST, GST_TAG_FLAG_META,
114 _("person(s) responsible for the recording"),
115 gst_tag_merge_strings_with_comma);
116 gst_tag_register_static (GST_TAG_ARTIST_SORTNAME, GST_TAG_FLAG_META,
118 _("artist sortname"),
119 _("person(s) responsible for the recording for sorting purposes"), NULL);
120 gst_tag_register_static (GST_TAG_ALBUM, GST_TAG_FLAG_META,
123 _("album containing this data"), gst_tag_merge_strings_with_comma);
124 gst_tag_register_static (GST_TAG_ALBUM_SORTNAME, GST_TAG_FLAG_META,
127 _("album containing this data for sorting purposes"), NULL);
128 gst_tag_register_static (GST_TAG_ALBUM_ARTIST, GST_TAG_FLAG_META,
131 _("The artist of the entire album, as it should be displayed"),
132 gst_tag_merge_strings_with_comma);
133 gst_tag_register_static (GST_TAG_ALBUM_ARTIST_SORTNAME, GST_TAG_FLAG_META,
135 _("album artist sortname"),
136 _("The artist of the entire album, as it should be sorted"), NULL);
137 gst_tag_register_static (GST_TAG_DATE, GST_TAG_FLAG_META, G_TYPE_DATE,
138 _("date"), _("date the data was created (as a GDate structure)"), NULL);
139 gst_tag_register_static (GST_TAG_DATE_TIME, GST_TAG_FLAG_META,
140 GST_TYPE_DATE_TIME, _("datetime"),
141 _("date and time the data was created (as a GstDateTime structure)"),
143 gst_tag_register_static (GST_TAG_GENRE, GST_TAG_FLAG_META,
146 _("genre this data belongs to"), gst_tag_merge_strings_with_comma);
147 gst_tag_register_static (GST_TAG_COMMENT, GST_TAG_FLAG_META,
150 _("free text commenting the data"), gst_tag_merge_use_first);
151 gst_tag_register_static (GST_TAG_EXTENDED_COMMENT, GST_TAG_FLAG_META,
153 _("extended comment"),
154 _("free text commenting the data in key=value or key[en]=comment form"),
155 gst_tag_merge_use_first);
156 gst_tag_register_static (GST_TAG_TRACK_NUMBER, GST_TAG_FLAG_META,
159 _("track number inside a collection"), gst_tag_merge_use_first);
160 gst_tag_register_static (GST_TAG_TRACK_COUNT, GST_TAG_FLAG_META,
163 _("count of tracks inside collection this track belongs to"),
164 gst_tag_merge_use_first);
165 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_FLAG_META,
168 _("disc number inside a collection"), gst_tag_merge_use_first);
169 gst_tag_register_static (GST_TAG_ALBUM_VOLUME_COUNT, GST_TAG_FLAG_META,
172 _("count of discs inside collection this disc belongs to"),
173 gst_tag_merge_use_first);
174 gst_tag_register_static (GST_TAG_LOCATION, GST_TAG_FLAG_META,
176 _("location"), _("Origin of media as a URI (location, where the "
177 "original of the file or stream is hosted)"),
178 gst_tag_merge_strings_with_comma);
179 gst_tag_register_static (GST_TAG_HOMEPAGE, GST_TAG_FLAG_META,
182 _("Homepage for this media (i.e. artist or movie homepage)"),
183 gst_tag_merge_strings_with_comma);
184 gst_tag_register_static (GST_TAG_DESCRIPTION, GST_TAG_FLAG_META,
185 G_TYPE_STRING, _("description"),
186 _("short text describing the content of the data"),
187 gst_tag_merge_strings_with_comma);
188 gst_tag_register_static (GST_TAG_VERSION, GST_TAG_FLAG_META, G_TYPE_STRING,
189 _("version"), _("version of this data"), NULL);
190 gst_tag_register_static (GST_TAG_ISRC, GST_TAG_FLAG_META, G_TYPE_STRING,
193 ("International Standard Recording Code - see http://www.ifpi.org/isrc/"),
195 /* FIXME: organization (fix what? tpm) */
196 gst_tag_register_static (GST_TAG_ORGANIZATION, GST_TAG_FLAG_META,
197 G_TYPE_STRING, _("organization"), _("organization"),
198 gst_tag_merge_strings_with_comma);
199 gst_tag_register_static (GST_TAG_COPYRIGHT, GST_TAG_FLAG_META,
200 G_TYPE_STRING, _("copyright"), _("copyright notice of the data"), NULL);
201 gst_tag_register_static (GST_TAG_COPYRIGHT_URI, GST_TAG_FLAG_META,
202 G_TYPE_STRING, _("copyright uri"),
203 _("URI to the copyright notice of the data"), NULL);
204 gst_tag_register_static (GST_TAG_ENCODED_BY, GST_TAG_FLAG_META, G_TYPE_STRING,
205 _("encoded by"), _("name of the encoding person or organization"),
206 gst_tag_merge_strings_with_comma);
207 gst_tag_register_static (GST_TAG_CONTACT, GST_TAG_FLAG_META,
209 _("contact"), _("contact information"), gst_tag_merge_strings_with_comma);
210 gst_tag_register_static (GST_TAG_LICENSE, GST_TAG_FLAG_META,
211 G_TYPE_STRING, _("license"), _("license of data"), NULL);
212 gst_tag_register_static (GST_TAG_LICENSE_URI, GST_TAG_FLAG_META,
213 G_TYPE_STRING, _("license uri"),
214 _("URI to the license of the data"), NULL);
215 gst_tag_register_static (GST_TAG_PERFORMER, GST_TAG_FLAG_META,
218 _("person(s) performing"), gst_tag_merge_strings_with_comma);
219 gst_tag_register_static (GST_TAG_COMPOSER, GST_TAG_FLAG_META,
222 _("person(s) who composed the recording"),
223 gst_tag_merge_strings_with_comma);
224 gst_tag_register_static (GST_TAG_CONDUCTOR, GST_TAG_FLAG_META,
227 _("conductor/performer refinement"), gst_tag_merge_strings_with_comma);
228 gst_tag_register_static (GST_TAG_DURATION, GST_TAG_FLAG_DECODED,
230 _("duration"), _("length in GStreamer time units (nanoseconds)"), NULL);
231 gst_tag_register_static (GST_TAG_CODEC, GST_TAG_FLAG_ENCODED,
234 _("codec the data is stored in"), gst_tag_merge_strings_with_comma);
235 gst_tag_register_static (GST_TAG_VIDEO_CODEC, GST_TAG_FLAG_ENCODED,
237 _("video codec"), _("codec the video data is stored in"), NULL);
238 gst_tag_register_static (GST_TAG_AUDIO_CODEC, GST_TAG_FLAG_ENCODED,
240 _("audio codec"), _("codec the audio data is stored in"), NULL);
241 gst_tag_register_static (GST_TAG_SUBTITLE_CODEC, GST_TAG_FLAG_ENCODED,
243 _("subtitle codec"), _("codec the subtitle data is stored in"), NULL);
244 gst_tag_register_static (GST_TAG_CONTAINER_FORMAT, GST_TAG_FLAG_ENCODED,
245 G_TYPE_STRING, _("container format"),
246 _("container format the data is stored in"), NULL);
247 gst_tag_register_static (GST_TAG_BITRATE, GST_TAG_FLAG_ENCODED,
248 G_TYPE_UINT, _("bitrate"), _("exact or average bitrate in bits/s"), NULL);
249 gst_tag_register_static (GST_TAG_NOMINAL_BITRATE, GST_TAG_FLAG_ENCODED,
250 G_TYPE_UINT, _("nominal bitrate"), _("nominal bitrate in bits/s"), NULL);
251 gst_tag_register_static (GST_TAG_MINIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
252 G_TYPE_UINT, _("minimum bitrate"), _("minimum bitrate in bits/s"), NULL);
253 gst_tag_register_static (GST_TAG_MAXIMUM_BITRATE, GST_TAG_FLAG_ENCODED,
254 G_TYPE_UINT, _("maximum bitrate"), _("maximum bitrate in bits/s"), NULL);
255 gst_tag_register_static (GST_TAG_ENCODER, GST_TAG_FLAG_ENCODED,
257 _("encoder"), _("encoder used to encode this stream"), NULL);
258 gst_tag_register_static (GST_TAG_ENCODER_VERSION, GST_TAG_FLAG_ENCODED,
260 _("encoder version"),
261 _("version of the encoder used to encode this stream"), NULL);
262 gst_tag_register_static (GST_TAG_SERIAL, GST_TAG_FLAG_ENCODED,
263 G_TYPE_UINT, _("serial"), _("serial number of track"), NULL);
264 gst_tag_register_static (GST_TAG_TRACK_GAIN, GST_TAG_FLAG_META,
265 G_TYPE_DOUBLE, _("replaygain track gain"), _("track gain in db"), NULL);
266 gst_tag_register_static (GST_TAG_TRACK_PEAK, GST_TAG_FLAG_META,
267 G_TYPE_DOUBLE, _("replaygain track peak"), _("peak of the track"), NULL);
268 gst_tag_register_static (GST_TAG_ALBUM_GAIN, GST_TAG_FLAG_META,
269 G_TYPE_DOUBLE, _("replaygain album gain"), _("album gain in db"), NULL);
270 gst_tag_register_static (GST_TAG_ALBUM_PEAK, GST_TAG_FLAG_META,
271 G_TYPE_DOUBLE, _("replaygain album peak"), _("peak of the album"), NULL);
272 gst_tag_register_static (GST_TAG_REFERENCE_LEVEL, GST_TAG_FLAG_META,
273 G_TYPE_DOUBLE, _("replaygain reference level"),
274 _("reference level of track and album gain values"), NULL);
275 gst_tag_register_static (GST_TAG_LANGUAGE_CODE, GST_TAG_FLAG_META,
276 G_TYPE_STRING, _("language code"),
277 _("language code for this stream, conforming to ISO-639-1 or ISO-639-2"),
279 gst_tag_register_static (GST_TAG_LANGUAGE_NAME, GST_TAG_FLAG_META,
280 G_TYPE_STRING, _("language name"),
281 _("freeform name of the language this stream is in"), NULL);
282 gst_tag_register_static (GST_TAG_IMAGE, GST_TAG_FLAG_META, GST_TYPE_SAMPLE,
283 _("image"), _("image related to this stream"), gst_tag_merge_use_first);
284 gst_tag_register_static (GST_TAG_PREVIEW_IMAGE, GST_TAG_FLAG_META,
286 /* TRANSLATORS: 'preview image' = image that shows a preview of the full image */
287 _("preview image"), _("preview image related to this stream"), NULL);
288 gst_tag_register_static (GST_TAG_ATTACHMENT, GST_TAG_FLAG_META,
289 GST_TYPE_SAMPLE, _("attachment"), _("file attached to this stream"),
290 gst_tag_merge_use_first);
291 gst_tag_register_static (GST_TAG_BEATS_PER_MINUTE, GST_TAG_FLAG_META,
292 G_TYPE_DOUBLE, _("beats per minute"),
293 _("number of beats per minute in audio"), NULL);
294 gst_tag_register_static (GST_TAG_KEYWORDS, GST_TAG_FLAG_META, G_TYPE_STRING,
295 _("keywords"), _("comma separated keywords describing the content"),
296 gst_tag_merge_strings_with_comma);
297 gst_tag_register_static (GST_TAG_GEO_LOCATION_NAME, GST_TAG_FLAG_META,
298 G_TYPE_STRING, _("geo location name"),
299 _("human readable descriptive location of where "
300 "the media has been recorded or produced"), NULL);
301 gst_tag_register_static (GST_TAG_GEO_LOCATION_LATITUDE, GST_TAG_FLAG_META,
302 G_TYPE_DOUBLE, _("geo location latitude"),
303 _("geo latitude location of where the media has been recorded or "
304 "produced in degrees according to WGS84 (zero at the equator, "
305 "negative values for southern latitudes)"), NULL);
306 gst_tag_register_static (GST_TAG_GEO_LOCATION_LONGITUDE, GST_TAG_FLAG_META,
307 G_TYPE_DOUBLE, _("geo location longitude"),
308 _("geo longitude location of where the media has been recorded or "
309 "produced in degrees according to WGS84 (zero at the prime meridian "
310 "in Greenwich/UK, negative values for western longitudes)"), NULL);
311 gst_tag_register_static (GST_TAG_GEO_LOCATION_ELEVATION, GST_TAG_FLAG_META,
312 G_TYPE_DOUBLE, _("geo location elevation"),
313 _("geo elevation of where the media has been recorded or produced in "
314 "meters according to WGS84 (zero is average sea level)"), NULL);
315 gst_tag_register_static (GST_TAG_GEO_LOCATION_COUNTRY, GST_TAG_FLAG_META,
316 G_TYPE_STRING, _("geo location country"),
317 _("country (english name) where the media has been recorded "
318 "or produced"), NULL);
319 gst_tag_register_static (GST_TAG_GEO_LOCATION_CITY, GST_TAG_FLAG_META,
320 G_TYPE_STRING, _("geo location city"),
321 _("city (english name) where the media has been recorded "
322 "or produced"), NULL);
323 gst_tag_register_static (GST_TAG_GEO_LOCATION_SUBLOCATION, GST_TAG_FLAG_META,
324 G_TYPE_STRING, _("geo location sublocation"),
325 _("a location within a city where the media has been produced "
326 "or created (e.g. the neighborhood)"), NULL);
327 gst_tag_register_static (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR,
328 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location horizontal error"),
329 _("expected error of the horizontal positioning measures (in meters)"),
331 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED,
332 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement speed"),
333 _("movement speed of the capturing device while performing the capture "
335 gst_tag_register_static (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION,
336 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location movement direction"),
337 _("indicates the movement direction of the device performing the capture"
338 " of 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_GEO_LOCATION_CAPTURE_DIRECTION,
342 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("geo location capture direction"),
343 _("indicates the direction the device is pointing to when capturing "
344 " a media. It is represented as degrees in floating point "
345 " representation, 0 means the geographic north, and increases "
347 gst_tag_register_static (GST_TAG_SHOW_NAME, GST_TAG_FLAG_META, G_TYPE_STRING,
348 /* TRANSLATORS: 'show name' = 'TV/radio/podcast show name' here */
350 _("Name of the tv/podcast/series show the media is from"),
351 gst_tag_merge_strings_with_comma);
352 gst_tag_register_static (GST_TAG_SHOW_SORTNAME, GST_TAG_FLAG_META,
354 /* TRANSLATORS: 'show sortname' = 'TV/radio/podcast show name as used for sorting purposes' here */
356 _("Name of the tv/podcast/series show the media is from, for sorting "
358 gst_tag_register_static (GST_TAG_SHOW_EPISODE_NUMBER, GST_TAG_FLAG_META,
359 G_TYPE_UINT, _("episode number"),
360 _("The episode number in the season the media is part of"),
361 gst_tag_merge_use_first);
362 gst_tag_register_static (GST_TAG_SHOW_SEASON_NUMBER, GST_TAG_FLAG_META,
363 G_TYPE_UINT, _("season number"),
364 _("The season number of the show the media is part of"),
365 gst_tag_merge_use_first);
366 gst_tag_register_static (GST_TAG_LYRICS, GST_TAG_FLAG_META, G_TYPE_STRING,
367 _("lyrics"), _("The lyrics of the media, commonly used for songs"),
368 gst_tag_merge_strings_with_comma);
369 gst_tag_register_static (GST_TAG_COMPOSER_SORTNAME, GST_TAG_FLAG_META,
370 G_TYPE_STRING, _("composer sortname"),
371 _("person(s) who composed the recording, for sorting purposes"), NULL);
372 gst_tag_register_static (GST_TAG_GROUPING, GST_TAG_FLAG_META, G_TYPE_STRING,
374 _("Groups related media that spans multiple tracks, like the different "
375 "pieces of a concerto. It is a higher level than a track, "
376 "but lower than an album"), NULL);
377 gst_tag_register_static (GST_TAG_USER_RATING, GST_TAG_FLAG_META, G_TYPE_UINT,
379 _("Rating attributed by a user. The higher the rank, "
380 "the more the user likes this media"), NULL);
381 gst_tag_register_static (GST_TAG_DEVICE_MANUFACTURER, GST_TAG_FLAG_META,
382 G_TYPE_STRING, _("device manufacturer"),
383 _("Manufacturer of the device used to create this media"), NULL);
384 gst_tag_register_static (GST_TAG_DEVICE_MODEL, GST_TAG_FLAG_META,
385 G_TYPE_STRING, _("device model"),
386 _("Model of the device used to create this media"), NULL);
387 gst_tag_register_static (GST_TAG_APPLICATION_NAME, GST_TAG_FLAG_META,
388 G_TYPE_STRING, _("application name"),
389 _("Application used to create the media"), NULL);
390 gst_tag_register_static (GST_TAG_APPLICATION_DATA, GST_TAG_FLAG_META,
391 GST_TYPE_SAMPLE, _("application data"),
392 _("Arbitrary application data to be serialized into the media"), NULL);
393 gst_tag_register_static (GST_TAG_IMAGE_ORIENTATION, GST_TAG_FLAG_META,
394 G_TYPE_STRING, _("image orientation"),
395 _("How the image should be rotated or flipped before display"), NULL);
396 gst_tag_register_static (GST_TAG_PUBLISHER, GST_TAG_FLAG_META,
399 _("Name of the label or publisher"), gst_tag_merge_strings_with_comma);
400 gst_tag_register_static (GST_TAG_INTERPRETED_BY, GST_TAG_FLAG_META,
403 _("Information about the people behind a remix and similar "
404 "interpretations"), gst_tag_merge_strings_with_comma);
405 gst_tag_register_static (GST_TAG_MIDI_BASE_NOTE, GST_TAG_FLAG_META,
407 _("midi-base-note"), _("Midi note number of the audio track."), NULL);
408 gst_tag_register_static (GST_TAG_PRIVATE_DATA, GST_TAG_FLAG_META,
410 _("private-data"), _("Private data"), gst_tag_merge_use_first);
415 * gst_tag_merge_use_first:
416 * @dest: (out caller-allocates): uninitialized GValue to store result in
417 * @src: GValue to copy from
419 * This is a convenience function for the func argument of gst_tag_register().
420 * It creates a copy of the first value from the list.
423 gst_tag_merge_use_first (GValue * dest, const GValue * src)
425 const GValue *ret = gst_value_list_get_value (src, 0);
427 g_value_init (dest, G_VALUE_TYPE (ret));
428 g_value_copy (ret, dest);
432 * gst_tag_merge_strings_with_comma:
433 * @dest: (out caller-allocates): uninitialized GValue to store result in
434 * @src: GValue to copy from
436 * This is a convenience function for the func argument of gst_tag_register().
437 * It concatenates all given strings using a comma. The tag must be registered
438 * as a G_TYPE_STRING or this function will fail.
441 gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src)
446 count = gst_value_list_get_size (src);
447 str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0)));
448 for (i = 1; i < count; i++) {
449 /* separator between two strings */
450 g_string_append (str, _(", "));
451 g_string_append (str,
452 g_value_get_string (gst_value_list_get_value (src, i)));
455 g_value_init (dest, G_TYPE_STRING);
456 g_value_take_string (dest, str->str);
457 g_string_free (str, FALSE);
461 gst_tag_lookup (const gchar * tag_name)
466 ret = g_hash_table_lookup (__tags, (gpointer) tag_name);
474 * @name: the name or identifier string
475 * @flag: a flag describing the type of tag info
476 * @type: the type this data is in
477 * @nick: human-readable name
478 * @blurb: a human-readable description about this tag
479 * @func: (allow-none) (scope call): function for merging multiple values of this tag, or %NULL
481 * Registers a new tag type for the use with GStreamer's type system. If a type
482 * with that name is already registered, that one is used.
483 * The old registration may have used a different type however. So don't rely
484 * on your supplied values.
486 * Important: if you do not supply a merge function the implication will be
487 * that there can only be one single value for this tag in a tag list and
488 * any additional values will silently be discarded when being added (unless
489 * #GST_TAG_MERGE_REPLACE, #GST_TAG_MERGE_REPLACE_ALL, or
490 * #GST_TAG_MERGE_PREPEND is used as merge mode, in which case the new
491 * value will replace the old one in the list).
493 * The merge function will be called from gst_tag_list_copy_value() when
494 * it is required that one or more values for a tag be condensed into
495 * one single value. This may happen from gst_tag_list_get_string(),
496 * gst_tag_list_get_int(), gst_tag_list_get_double() etc. What will happen
497 * exactly in that case depends on how the tag was registered and if a
498 * merge function was supplied and if so which one.
500 * Two default merge functions are provided: gst_tag_merge_use_first() and
501 * gst_tag_merge_strings_with_comma().
504 gst_tag_register (const gchar * name, GstTagFlag flag, GType type,
505 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
507 g_return_if_fail (name != NULL);
508 g_return_if_fail (nick != NULL);
509 g_return_if_fail (blurb != NULL);
510 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
512 gst_tag_register_static (g_intern_string (name), flag, type,
513 g_intern_string (nick), g_intern_string (blurb), func);
517 * gst_tag_register_static:
518 * @name: the name or identifier string (string constant)
519 * @flag: a flag describing the type of tag info
520 * @type: the type this data is in
521 * @nick: human-readable name or short description (string constant)
522 * @blurb: a human-readable description for this tag (string constant)
523 * @func: (allow-none) (scope call): function for merging multiple values of this tag, or %NULL
525 * Registers a new tag type for the use with GStreamer's type system.
527 * Same as gst_tag_register(), but @name, @nick, and @blurb must be
528 * static strings or inlined strings, as they will not be copied. (GStreamer
529 * plugins will be made resident once loaded, so this function can be used
530 * even from dynamically loaded plugins.)
533 gst_tag_register_static (const gchar * name, GstTagFlag flag, GType type,
534 const gchar * nick, const gchar * blurb, GstTagMergeFunc func)
538 g_return_if_fail (name != NULL);
539 g_return_if_fail (nick != NULL);
540 g_return_if_fail (blurb != NULL);
541 g_return_if_fail (type != 0 && type != GST_TYPE_LIST);
543 info = gst_tag_lookup (name);
546 g_return_if_fail (info->type == type);
550 info = g_slice_new (GstTagInfo);
553 info->name_quark = g_quark_from_static_string (name);
556 info->merge_func = func;
559 g_hash_table_insert (__tags, (gpointer) name, info);
565 * @tag: name of the tag
567 * Checks if the given type is already registered.
569 * Returns: %TRUE if the type is already registered
572 gst_tag_exists (const gchar * tag)
574 g_return_val_if_fail (tag != NULL, FALSE);
576 return gst_tag_lookup (tag) != NULL;
583 * Gets the #GType used for this tag.
585 * Returns: the #GType of this tag
588 gst_tag_get_type (const gchar * tag)
592 g_return_val_if_fail (tag != NULL, 0);
593 info = gst_tag_lookup (tag);
594 g_return_val_if_fail (info != NULL, 0);
603 * Returns the human-readable name of this tag, You must not change or free
606 * Returns: the human-readable name of this tag
609 gst_tag_get_nick (const gchar * tag)
613 g_return_val_if_fail (tag != NULL, NULL);
614 info = gst_tag_lookup (tag);
615 g_return_val_if_fail (info != NULL, NULL);
621 * gst_tag_get_description:
624 * Returns the human-readable description of this tag, You must not change or
627 * Returns: the human-readable description of this tag
630 gst_tag_get_description (const gchar * tag)
634 g_return_val_if_fail (tag != NULL, NULL);
635 info = gst_tag_lookup (tag);
636 g_return_val_if_fail (info != NULL, NULL);
645 * Gets the flag of @tag.
647 * Returns: the flag of this tag.
650 gst_tag_get_flag (const gchar * tag)
654 g_return_val_if_fail (tag != NULL, GST_TAG_FLAG_UNDEFINED);
655 info = gst_tag_lookup (tag);
656 g_return_val_if_fail (info != NULL, GST_TAG_FLAG_UNDEFINED);
665 * Checks if the given tag is fixed. A fixed tag can only contain one value.
666 * Unfixed tags can contain lists of values.
668 * Returns: %TRUE, if the given tag is fixed.
671 gst_tag_is_fixed (const gchar * tag)
675 g_return_val_if_fail (tag != NULL, FALSE);
676 info = gst_tag_lookup (tag);
677 g_return_val_if_fail (info != NULL, FALSE);
679 return info->merge_func == NULL;
682 /* takes ownership of the structure */
684 gst_tag_list_new_internal (GstStructure * s, GstTagScope scope)
686 GstTagList *tag_list;
688 g_assert (s != NULL);
690 tag_list = (GstTagList *) g_slice_new (GstTagListImpl);
692 gst_mini_object_init (GST_MINI_OBJECT_CAST (tag_list), 0, GST_TYPE_TAG_LIST,
693 (GstMiniObjectCopyFunction) __gst_tag_list_copy, NULL,
694 (GstMiniObjectFreeFunction) __gst_tag_list_free);
696 GST_TAG_LIST_STRUCTURE (tag_list) = s;
697 GST_TAG_LIST_SCOPE (tag_list) = scope;
699 #ifdef DEBUG_REFCOUNT
700 GST_CAT_TRACE (GST_CAT_TAGS, "created taglist %p", tag_list);
707 __gst_tag_list_free (GstTagList * list)
709 g_return_if_fail (GST_IS_TAG_LIST (list));
711 #ifdef DEBUG_REFCOUNT
712 GST_CAT_TRACE (GST_CAT_TAGS, "freeing taglist %p", list);
715 gst_structure_free (GST_TAG_LIST_STRUCTURE (list));
717 g_slice_free1 (sizeof (GstTagListImpl), list);
721 __gst_tag_list_copy (const GstTagList * list)
723 const GstStructure *s;
725 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
727 s = GST_TAG_LIST_STRUCTURE (list);
728 return gst_tag_list_new_internal (gst_structure_copy (s),
729 GST_TAG_LIST_SCOPE (list));
733 * gst_tag_list_new_empty:
735 * Creates a new empty GstTagList.
737 * Free-function: gst_tag_list_unref
739 * Returns: (transfer full): An empty tag list
742 gst_tag_list_new_empty (void)
745 GstTagList *tag_list;
747 s = gst_structure_new_id_empty (GST_QUARK (TAGLIST));
748 tag_list = gst_tag_list_new_internal (s, GST_TAG_SCOPE_STREAM);
755 * @...: %NULL-terminated list of values to set
757 * Creates a new taglist and appends the values for the given tags. It expects
758 * tag-value pairs like gst_tag_list_add(), and a %NULL terminator after the
759 * last pair. The type of the values is implicit and is documented in the API
760 * reference, but can also be queried at runtime with gst_tag_get_type(). It
761 * is an error to pass a value of a type not matching the tag type into this
762 * function. The tag list will make copies of any arguments passed
763 * (e.g. strings, buffers).
765 * After creation you might also want to set a #GstTagScope on the returned
766 * taglist to signal if the contained tags are global or stream tags. By
767 * default stream scope is assumes. See gst_tag_list_set_scope().
769 * Free-function: gst_tag_list_unref
771 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
772 * when no longer needed.
775 gst_tag_list_new (const gchar * tag, ...)
780 g_return_val_if_fail (tag != NULL, NULL);
782 list = gst_tag_list_new_empty ();
783 va_start (args, tag);
784 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
791 * gst_tag_list_new_valist:
792 * @var_args: tag / value pairs to set
794 * Just like gst_tag_list_new(), only that it takes a va_list argument.
795 * Useful mostly for language bindings.
797 * Free-function: gst_tag_list_unref
799 * Returns: (transfer full): a new #GstTagList. Free with gst_tag_list_unref()
800 * when no longer needed.
803 gst_tag_list_new_valist (va_list var_args)
808 list = gst_tag_list_new_empty ();
810 tag = va_arg (var_args, gchar *);
811 gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
817 * gst_tag_list_set_scope:
818 * @list: a #GstTagList
819 * @scope: new scope for @list
821 * Sets the scope of @list to @scope. By default the scope
822 * of a taglist is stream scope.
826 gst_tag_list_set_scope (GstTagList * list, GstTagScope scope)
828 g_return_if_fail (GST_IS_TAG_LIST (list));
829 g_return_if_fail (gst_tag_list_is_writable (list));
831 GST_TAG_LIST_SCOPE (list) = scope;
835 * gst_tag_list_get_scope:
836 * @list: a #GstTagList
838 * Gets the scope of @list.
840 * Returns: The scope of @list
843 gst_tag_list_get_scope (const GstTagList * list)
845 g_return_val_if_fail (GST_IS_TAG_LIST (list), GST_TAG_SCOPE_STREAM);
847 return GST_TAG_LIST_SCOPE (list);
851 * gst_tag_list_to_string:
852 * @list: a #GstTagList
854 * Serializes a tag list to a string.
856 * Returns: (nullable): a newly-allocated string, or %NULL in case of
857 * an error. The string must be freed with g_free() when no longer
861 gst_tag_list_to_string (const GstTagList * list)
863 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
865 return gst_structure_to_string (GST_TAG_LIST_STRUCTURE (list));
869 * gst_tag_list_new_from_string:
870 * @str: a string created with gst_tag_list_to_string()
872 * Deserializes a tag list.
874 * Returns: (nullable): a new #GstTagList, or %NULL in case of an
878 gst_tag_list_new_from_string (const gchar * str)
880 GstTagList *tag_list;
883 g_return_val_if_fail (str != NULL, NULL);
884 g_return_val_if_fail (g_str_has_prefix (str, "taglist"), NULL);
886 s = gst_structure_from_string (str, NULL);
890 tag_list = gst_tag_list_new_internal (s, GST_TAG_SCOPE_STREAM);
896 * gst_tag_list_n_tags:
897 * @list: A #GstTagList.
899 * Get the number of tags in @list.
901 * Returns: The number of tags in @list.
904 gst_tag_list_n_tags (const GstTagList * list)
906 g_return_val_if_fail (list != NULL, 0);
907 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
909 return gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list));
913 * gst_tag_list_nth_tag_name:
914 * @list: A #GstTagList.
917 * Get the name of the tag in @list at @index.
919 * Returns: The name of the tag at @index.
922 gst_tag_list_nth_tag_name (const GstTagList * list, guint index)
924 g_return_val_if_fail (list != NULL, 0);
925 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
927 return gst_structure_nth_field_name (GST_TAG_LIST_STRUCTURE (list), index);
931 * gst_tag_list_is_empty:
932 * @list: A #GstTagList.
934 * Checks if the given taglist is empty.
936 * Returns: %TRUE if the taglist is empty, otherwise %FALSE.
939 gst_tag_list_is_empty (const GstTagList * list)
941 g_return_val_if_fail (list != NULL, FALSE);
942 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
944 return (gst_structure_n_fields (GST_TAG_LIST_STRUCTURE (list)) == 0);
948 gst_tag_list_fields_equal (const GValue * value1, const GValue * value2)
952 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL)
955 /* fields not equal: add some tolerance for doubles, otherwise bail out */
956 if (!G_VALUE_HOLDS_DOUBLE (value1) || !G_VALUE_HOLDS_DOUBLE (value2))
959 d1 = g_value_get_double (value1);
960 d2 = g_value_get_double (value2);
962 /* This will only work for 'normal' values and values around 0,
963 * which should be good enough for our purposes here
964 * FIXME: maybe add this to gst_value_compare_double() ? */
965 return (fabs (d1 - d2) < 0.0000001);
969 * gst_tag_list_is_equal:
970 * @list1: a #GstTagList.
971 * @list2: a #GstTagList.
973 * Checks if the two given taglists are equal.
975 * Returns: %TRUE if the taglists are equal, otherwise %FALSE
978 gst_tag_list_is_equal (const GstTagList * list1, const GstTagList * list2)
980 const GstStructure *s1, *s2;
981 gint num_fields1, num_fields2, i;
983 g_return_val_if_fail (GST_IS_TAG_LIST (list1), FALSE);
984 g_return_val_if_fail (GST_IS_TAG_LIST (list2), FALSE);
986 /* we don't just use gst_structure_is_equal() here so we can add some
987 * tolerance for doubles, though maybe we should just add that to
988 * gst_value_compare_double() as well? */
989 s1 = GST_TAG_LIST_STRUCTURE (list1);
990 s2 = GST_TAG_LIST_STRUCTURE (list2);
992 num_fields1 = gst_structure_n_fields (s1);
993 num_fields2 = gst_structure_n_fields (s2);
995 if (num_fields1 != num_fields2)
998 for (i = 0; i < num_fields1; i++) {
999 const GValue *value1, *value2;
1000 const gchar *tag_name;
1002 tag_name = gst_structure_nth_field_name (s1, i);
1003 value1 = gst_structure_get_value (s1, tag_name);
1004 value2 = gst_structure_get_value (s2, tag_name);
1009 if (!gst_tag_list_fields_equal (value1, value2))
1019 GstTagMergeMode mode;
1024 gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
1025 const gchar * tag, const GValue * value, GstTagInfo * info)
1027 GstStructure *list = GST_TAG_LIST_STRUCTURE (tag_list);
1028 const GValue *value2;
1032 info = gst_tag_lookup (tag);
1033 if (G_UNLIKELY (info == NULL)) {
1034 g_warning ("unknown tag '%s'", tag);
1039 if (G_UNLIKELY (!G_VALUE_HOLDS (value, info->type) &&
1040 !GST_VALUE_HOLDS_LIST (value))) {
1041 g_warning ("tag '%s' should hold value of type '%s', but value of "
1042 "type '%s' passed", info->nick, g_type_name (info->type),
1043 g_type_name (G_VALUE_TYPE (value)));
1047 tag_quark = info->name_quark;
1049 if (info->merge_func
1050 && (value2 = gst_structure_id_get_value (list, tag_quark)) != NULL) {
1051 GValue dest = { 0, };
1054 case GST_TAG_MERGE_REPLACE_ALL:
1055 case GST_TAG_MERGE_REPLACE:
1056 gst_structure_id_set_value (list, tag_quark, value);
1058 case GST_TAG_MERGE_PREPEND:
1059 if (GST_VALUE_HOLDS_LIST (value2) && !GST_VALUE_HOLDS_LIST (value))
1060 gst_value_list_prepend_value ((GValue *) value2, value);
1062 gst_value_list_merge (&dest, value, value2);
1063 gst_structure_id_take_value (list, tag_quark, &dest);
1066 case GST_TAG_MERGE_APPEND:
1067 if (GST_VALUE_HOLDS_LIST (value2) && !GST_VALUE_HOLDS_LIST (value))
1068 gst_value_list_append_value ((GValue *) value2, value);
1070 gst_value_list_merge (&dest, value2, value);
1071 gst_structure_id_take_value (list, tag_quark, &dest);
1074 case GST_TAG_MERGE_KEEP:
1075 case GST_TAG_MERGE_KEEP_ALL:
1078 g_assert_not_reached ();
1083 case GST_TAG_MERGE_APPEND:
1084 case GST_TAG_MERGE_KEEP:
1085 if (gst_structure_id_get_value (list, tag_quark) != NULL)
1088 case GST_TAG_MERGE_REPLACE_ALL:
1089 case GST_TAG_MERGE_REPLACE:
1090 case GST_TAG_MERGE_PREPEND:
1091 gst_structure_id_set_value (list, tag_quark, value);
1093 case GST_TAG_MERGE_KEEP_ALL:
1096 g_assert_not_reached ();
1103 gst_tag_list_copy_foreach (GQuark tag_quark, const GValue * value,
1106 GstTagCopyData *copy = (GstTagCopyData *) user_data;
1109 tag = g_quark_to_string (tag_quark);
1110 gst_tag_list_add_value_internal (copy->list, copy->mode, tag, value, NULL);
1116 * gst_tag_list_insert:
1117 * @into: list to merge into
1118 * @from: list to merge from
1119 * @mode: the mode to use
1121 * Inserts the tags of the @from list into the first list using the given mode.
1124 gst_tag_list_insert (GstTagList * into, const GstTagList * from,
1125 GstTagMergeMode mode)
1127 GstTagCopyData data;
1129 g_return_if_fail (GST_IS_TAG_LIST (into));
1130 g_return_if_fail (gst_tag_list_is_writable (into));
1131 g_return_if_fail (GST_IS_TAG_LIST (from));
1132 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1136 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1137 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (into));
1139 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (from),
1140 gst_tag_list_copy_foreach, &data);
1144 * gst_tag_list_merge:
1145 * @list1: (allow-none): first list to merge
1146 * @list2: (allow-none): second list to merge
1147 * @mode: the mode to use
1149 * Merges the two given lists into a new list. If one of the lists is %NULL, a
1150 * copy of the other is returned. If both lists are %NULL, %NULL is returned.
1152 * Free-function: gst_tag_list_unref
1154 * Returns: (transfer full) (nullable): the new list
1157 gst_tag_list_merge (const GstTagList * list1, const GstTagList * list2,
1158 GstTagMergeMode mode)
1160 GstTagList *list1_cp;
1161 const GstTagList *list2_cp;
1163 g_return_val_if_fail (list1 == NULL || GST_IS_TAG_LIST (list1), NULL);
1164 g_return_val_if_fail (list2 == NULL || GST_IS_TAG_LIST (list2), NULL);
1165 g_return_val_if_fail (GST_TAG_MODE_IS_VALID (mode), NULL);
1167 /* nothing to merge */
1168 if (!list1 && !list2) {
1172 /* create empty list, we need to do this to correctly handling merge modes */
1173 list1_cp = (list1) ? gst_tag_list_copy (list1) : gst_tag_list_new_empty ();
1174 list2_cp = (list2) ? list2 : gst_tag_list_new_empty ();
1176 gst_tag_list_insert (list1_cp, list2_cp, mode);
1179 gst_tag_list_unref ((GstTagList *) list2_cp);
1185 * gst_tag_list_get_tag_size:
1187 * @tag: the tag to query
1189 * Checks how many value are stored in this tag list for the given tag.
1191 * Returns: The number of tags stored
1194 gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag)
1196 const GValue *value;
1198 g_return_val_if_fail (GST_IS_TAG_LIST (list), 0);
1200 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1203 if (G_VALUE_TYPE (value) != GST_TYPE_LIST)
1206 return gst_value_list_get_size (value);
1211 * @list: list to set tags in
1212 * @mode: the mode to use
1214 * @...: %NULL-terminated list of values to set
1216 * Sets the values for the given tags using the specified mode.
1219 gst_tag_list_add (GstTagList * list, GstTagMergeMode mode, 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 (list, mode, tag, args);
1235 * gst_tag_list_add_values:
1236 * @list: list to set tags in
1237 * @mode: the mode to use
1239 * @...: GValues to set
1241 * Sets the GValues for the given tags using the specified mode.
1244 gst_tag_list_add_values (GstTagList * list, GstTagMergeMode mode,
1245 const gchar * tag, ...)
1249 g_return_if_fail (GST_IS_TAG_LIST (list));
1250 g_return_if_fail (gst_tag_list_is_writable (list));
1251 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1252 g_return_if_fail (tag != NULL);
1254 va_start (args, tag);
1255 gst_tag_list_add_valist_values (list, mode, tag, args);
1260 * gst_tag_list_add_valist:
1261 * @list: list to set tags in
1262 * @mode: the mode to use
1264 * @var_args: tag / value pairs to set
1266 * Sets the values for the given tags using the specified mode.
1269 gst_tag_list_add_valist (GstTagList * list, GstTagMergeMode mode,
1270 const gchar * tag, va_list var_args)
1273 gchar *error = NULL;
1275 g_return_if_fail (GST_IS_TAG_LIST (list));
1276 g_return_if_fail (gst_tag_list_is_writable (list));
1277 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1278 g_return_if_fail (tag != NULL);
1280 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1281 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1284 while (tag != NULL) {
1285 GValue value = { 0, };
1287 info = gst_tag_lookup (tag);
1288 if (G_UNLIKELY (info == NULL)) {
1289 g_warning ("unknown tag '%s'", tag);
1292 G_VALUE_COLLECT_INIT (&value, info->type, var_args, 0, &error);
1294 g_warning ("%s: %s", G_STRLOC, error);
1296 /* we purposely leak the value here, it might not be
1297 * in a sane state if an error condition occoured
1301 /* Facilitate GstBuffer -> GstSample transition */
1302 if (G_UNLIKELY (info->type == GST_TYPE_SAMPLE &&
1303 !GST_IS_SAMPLE (value.data[0].v_pointer))) {
1304 g_warning ("Expected GstSample argument for tag '%s'", tag);
1306 gst_tag_list_add_value_internal (list, mode, tag, &value, info);
1308 g_value_unset (&value);
1309 tag = va_arg (var_args, gchar *);
1314 * gst_tag_list_add_valist_values:
1315 * @list: list to set tags in
1316 * @mode: the mode to use
1318 * @var_args: tag / GValue pairs to set
1320 * Sets the GValues for the given tags using the specified mode.
1323 gst_tag_list_add_valist_values (GstTagList * list, GstTagMergeMode mode,
1324 const gchar * tag, va_list var_args)
1326 g_return_if_fail (GST_IS_TAG_LIST (list));
1327 g_return_if_fail (gst_tag_list_is_writable (list));
1328 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1329 g_return_if_fail (tag != NULL);
1331 if (mode == GST_TAG_MERGE_REPLACE_ALL) {
1332 gst_structure_remove_all_fields (GST_TAG_LIST_STRUCTURE (list));
1335 while (tag != NULL) {
1338 info = gst_tag_lookup (tag);
1339 if (G_UNLIKELY (info == NULL)) {
1340 g_warning ("unknown tag '%s'", tag);
1343 gst_tag_list_add_value_internal (list, mode, tag, va_arg (var_args,
1345 tag = va_arg (var_args, gchar *);
1350 * gst_tag_list_add_value:
1351 * @list: list to set tags in
1352 * @mode: the mode to use
1354 * @value: GValue for this tag
1356 * Sets the GValue for a given tag using the specified mode.
1359 gst_tag_list_add_value (GstTagList * list, GstTagMergeMode mode,
1360 const gchar * tag, const GValue * value)
1362 g_return_if_fail (GST_IS_TAG_LIST (list));
1363 g_return_if_fail (gst_tag_list_is_writable (list));
1364 g_return_if_fail (GST_TAG_MODE_IS_VALID (mode));
1365 g_return_if_fail (tag != NULL);
1367 gst_tag_list_add_value_internal (list, mode, tag, value, NULL);
1371 * gst_tag_list_remove_tag:
1372 * @list: list to remove tag from
1373 * @tag: tag to remove
1375 * Removes the given tag from the taglist.
1378 gst_tag_list_remove_tag (GstTagList * list, const gchar * tag)
1380 g_return_if_fail (GST_IS_TAG_LIST (list));
1381 g_return_if_fail (gst_tag_list_is_writable (list));
1382 g_return_if_fail (tag != NULL);
1384 gst_structure_remove_field (GST_TAG_LIST_STRUCTURE (list), tag);
1389 GstTagForeachFunc func;
1390 const GstTagList *tag_list;
1396 structure_foreach_wrapper (GQuark field_id, const GValue * value,
1399 TagForeachData *data = (TagForeachData *) user_data;
1401 data->func (data->tag_list, g_quark_to_string (field_id), data->data);
1406 * gst_tag_list_foreach:
1407 * @list: list to iterate over
1408 * @func: (scope call): function to be called for each tag
1409 * @user_data: (closure): user specified data
1411 * Calls the given function for each tag inside the tag list. Note that if there
1412 * is no tag, the function won't be called at all.
1415 gst_tag_list_foreach (const GstTagList * list, GstTagForeachFunc func,
1418 TagForeachData data;
1420 g_return_if_fail (GST_IS_TAG_LIST (list));
1421 g_return_if_fail (func != NULL);
1424 data.tag_list = list;
1425 data.data = user_data;
1426 gst_structure_foreach (GST_TAG_LIST_STRUCTURE (list),
1427 structure_foreach_wrapper, &data);
1431 * gst_tag_list_get_value_index:
1432 * @list: a #GstTagList
1433 * @tag: tag to read out
1434 * @index: number of entry to read out
1436 * Gets the value that is at the given index for the given tag in the given
1439 * Returns: (transfer none) (nullable): The GValue for the specified
1440 * entry or %NULL if the tag wasn't available or the tag
1441 * doesn't have as many entries
1444 gst_tag_list_get_value_index (const GstTagList * list, const gchar * tag,
1447 const GValue *value;
1449 g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
1450 g_return_val_if_fail (tag != NULL, NULL);
1452 value = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1456 if (GST_VALUE_HOLDS_LIST (value)) {
1457 if (index >= gst_value_list_get_size (value))
1459 return gst_value_list_get_value (value, index);
1468 * gst_tag_list_copy_value:
1469 * @dest: (out caller-allocates): uninitialized #GValue to copy into
1470 * @list: list to get the tag from
1471 * @tag: tag to read out
1473 * Copies the contents for the given tag into the value,
1474 * merging multiple values into one if multiple values are associated
1476 * You must g_value_unset() the value after use.
1478 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1482 gst_tag_list_copy_value (GValue * dest, const GstTagList * list,
1487 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1488 g_return_val_if_fail (tag != NULL, FALSE);
1489 g_return_val_if_fail (dest != NULL, FALSE);
1490 g_return_val_if_fail (G_VALUE_TYPE (dest) == 0, FALSE);
1492 src = gst_structure_get_value (GST_TAG_LIST_STRUCTURE (list), tag);
1496 if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1497 GstTagInfo *info = gst_tag_lookup (tag);
1502 /* must be there or lists aren't allowed */
1503 g_assert (info->merge_func);
1504 info->merge_func (dest, src);
1506 g_value_init (dest, G_VALUE_TYPE (src));
1507 g_value_copy (src, dest);
1512 /* FIXME 2.0: this whole merge function business is overdesigned, and the
1513 * _get_foo() API is misleading as well - how many application developers will
1514 * expect gst_tag_list_get_string (list, GST_TAG_ARTIST, &val) might return a
1515 * string with multiple comma-separated artists? _get_foo() should just be
1516 * a convenience wrapper around _get_foo_index (list, tag, 0, &val),
1517 * supplemented by a special _tag_list_get_string_merged() function if needed
1518 * (unless someone can actually think of real use cases where the merge
1519 * function is not 'use first' for non-strings and merge for strings) */
1521 /***** evil macros to get all the gst_tag_list_get_*() functions right *****/
1523 #define TAG_MERGE_FUNCS(name,type,ret) \
1525 gst_tag_list_get_ ## name (const GstTagList *list, const gchar *tag, \
1528 GValue v = { 0, }; \
1530 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1531 g_return_val_if_fail (tag != NULL, FALSE); \
1532 g_return_val_if_fail (value != NULL, FALSE); \
1534 if (!gst_tag_list_copy_value (&v, list, tag)) \
1536 *value = COPY_FUNC (g_value_get_ ## name (&v)); \
1537 g_value_unset (&v); \
1542 gst_tag_list_get_ ## name ## _index (const GstTagList *list, \
1544 guint index, type *value) \
1548 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); \
1549 g_return_val_if_fail (tag != NULL, FALSE); \
1550 g_return_val_if_fail (value != NULL, FALSE); \
1552 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) \
1554 *value = COPY_FUNC (g_value_get_ ## name (v)); \
1558 #define COPY_FUNC /**/
1560 * gst_tag_list_get_boolean:
1561 * @list: a #GstTagList to get the tag from
1562 * @tag: tag to read out
1563 * @value: (out): location for the result
1565 * Copies the contents for the given tag into the value, merging multiple values
1566 * into one if multiple values are associated with the tag.
1568 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1572 * gst_tag_list_get_boolean_index:
1573 * @list: a #GstTagList to get the tag from
1574 * @tag: tag to read out
1575 * @index: number of entry to read out
1576 * @value: (out): location for the result
1578 * Gets the value that is at the given index for the given tag in the given
1581 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1584 TAG_MERGE_FUNCS (boolean, gboolean, TRUE);
1586 * gst_tag_list_get_int:
1587 * @list: a #GstTagList to get the tag from
1588 * @tag: tag to read out
1589 * @value: (out): location for the result
1591 * Copies the contents for the given tag into the value, merging multiple values
1592 * into one if multiple values are associated with the tag.
1594 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1598 * gst_tag_list_get_int_index:
1599 * @list: a #GstTagList to get the tag from
1600 * @tag: tag to read out
1601 * @index: number of entry to read out
1602 * @value: (out): location for the result
1604 * Gets the value that is at the given index for the given tag in the given
1607 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1610 TAG_MERGE_FUNCS (int, gint, TRUE);
1612 * gst_tag_list_get_uint:
1613 * @list: a #GstTagList to get the tag from
1614 * @tag: tag to read out
1615 * @value: (out): location for the result
1617 * Copies the contents for the given tag into the value, merging multiple values
1618 * into one if multiple values are associated with the tag.
1620 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1624 * gst_tag_list_get_uint_index:
1625 * @list: a #GstTagList to get the tag from
1626 * @tag: tag to read out
1627 * @index: number of entry to read out
1628 * @value: (out): location for the result
1630 * Gets the value that is at the given index for the given tag in the given
1633 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1636 TAG_MERGE_FUNCS (uint, guint, TRUE);
1638 * gst_tag_list_get_int64_index:
1639 * @list: a #GstTagList to get the tag from
1640 * @tag: tag to read out
1641 * @index: number of entry to read out
1642 * @value: (out): location for the result
1644 * Gets the value that is at the given index for the given tag in the given
1647 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1650 TAG_MERGE_FUNCS (int64, gint64, TRUE);
1652 * gst_tag_list_get_uint64:
1653 * @list: a #GstTagList to get the tag from
1654 * @tag: tag to read out
1655 * @value: (out): location for the result
1657 * Copies the contents for the given tag into the value, merging multiple values
1658 * into one if multiple values are associated with the tag.
1660 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1664 * gst_tag_list_get_uint64_index:
1665 * @list: a #GstTagList to get the tag from
1666 * @tag: tag to read out
1667 * @index: number of entry to read out
1668 * @value: (out): location for the result
1670 * Gets the value that is at the given index for the given tag in the given
1673 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1676 TAG_MERGE_FUNCS (uint64, guint64, TRUE);
1678 * gst_tag_list_get_float:
1679 * @list: a #GstTagList to get the tag from
1680 * @tag: tag to read out
1681 * @value: (out): location for the result
1683 * Copies the contents for the given tag into the value, merging multiple values
1684 * into one if multiple values are associated with the tag.
1686 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1690 * gst_tag_list_get_float_index:
1691 * @list: a #GstTagList to get the tag from
1692 * @tag: tag to read out
1693 * @index: number of entry to read out
1694 * @value: (out): location for the result
1696 * Gets the value that is at the given index for the given tag in the given
1699 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1702 TAG_MERGE_FUNCS (float, gfloat, TRUE);
1704 * gst_tag_list_get_double:
1705 * @list: a #GstTagList to get the tag from
1706 * @tag: tag to read out
1707 * @value: (out): location for the result
1709 * Copies the contents for the given tag into the value, merging multiple values
1710 * into one if multiple values are associated with the tag.
1712 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1716 * gst_tag_list_get_double_index:
1717 * @list: a #GstTagList to get the tag from
1718 * @tag: tag to read out
1719 * @index: number of entry to read out
1720 * @value: (out): location for the result
1722 * Gets the value that is at the given index for the given tag in the given
1725 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1728 TAG_MERGE_FUNCS (double, gdouble, TRUE);
1730 * gst_tag_list_get_pointer:
1731 * @list: a #GstTagList to get the tag from
1732 * @tag: tag to read out
1733 * @value: (out) (transfer none): location for the result
1735 * Copies the contents for the given tag into the value, merging multiple values
1736 * into one if multiple values are associated with the tag.
1738 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1742 * gst_tag_list_get_pointer_index:
1743 * @list: a #GstTagList to get the tag from
1744 * @tag: tag to read out
1745 * @index: number of entry to read out
1746 * @value: (out) (transfer none): location for the result
1748 * Gets the value that is at the given index for the given tag in the given
1751 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1754 TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL));
1756 static inline gchar *
1757 _gst_strdup0 (const gchar * s)
1759 if (s == NULL || *s == '\0')
1762 return g_strdup (s);
1766 #define COPY_FUNC _gst_strdup0
1769 * gst_tag_list_get_string:
1770 * @list: a #GstTagList to get the tag from
1771 * @tag: tag to read out
1772 * @value: (out callee-allocates) (transfer full): location for the result
1774 * Copies the contents for the given tag into the value, possibly merging
1775 * multiple values into one if multiple values are associated with the tag.
1777 * Use gst_tag_list_get_string_index (list, tag, 0, value) if you want
1778 * to retrieve the first string associated with this tag unmodified.
1780 * The resulting string in @value will be in UTF-8 encoding and should be
1781 * freed by the caller using g_free when no longer needed. The
1782 * returned string is also guaranteed to be non-%NULL and non-empty.
1784 * Free-function: g_free
1786 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1790 * gst_tag_list_get_string_index:
1791 * @list: a #GstTagList to get the tag from
1792 * @tag: tag to read out
1793 * @index: number of entry to read out
1794 * @value: (out callee-allocates) (transfer full): location for the result
1796 * Gets the value that is at the given index for the given tag in the given
1799 * The resulting string in @value will be in UTF-8 encoding and should be
1800 * freed by the caller using g_free when no longer needed. The
1801 * returned string is also guaranteed to be non-%NULL and non-empty.
1803 * Free-function: g_free
1805 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1808 TAG_MERGE_FUNCS (string, gchar *, (*value != NULL));
1811 *FIXME 2.0: Instead of _peek (non-copy) and _get (copy), we could have
1812 * _get (non-copy) and _dup (copy) for strings, seems more
1816 * gst_tag_list_peek_string_index:
1817 * @list: a #GstTagList to get the tag from
1818 * @tag: tag to read out
1819 * @index: number of entry to read out
1820 * @value: (out) (transfer none): location for the result
1822 * Peeks at the value that is at the given index for the given tag in the given
1825 * The resulting string in @value will be in UTF-8 encoding and doesn't need
1826 * to be freed by the caller. The returned string is also guaranteed to
1827 * be non-%NULL and non-empty.
1829 * Returns: %TRUE, if a value was set, %FALSE if the tag didn't exist in the
1833 gst_tag_list_peek_string_index (const GstTagList * list,
1834 const gchar * tag, guint index, const gchar ** value)
1838 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1839 g_return_val_if_fail (tag != NULL, FALSE);
1840 g_return_val_if_fail (value != NULL, FALSE);
1842 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1844 *value = g_value_get_string (v);
1845 return *value != NULL && **value != '\0';
1849 * gst_tag_list_get_date:
1850 * @list: a #GstTagList to get the tag from
1851 * @tag: tag to read out
1852 * @value: (out callee-allocates) (transfer full): address of a GDate pointer
1853 * variable to store the result into
1855 * Copies the first date for the given tag in the taglist into the variable
1856 * pointed to by @value. Free the date with g_date_free() when it is no longer
1859 * Free-function: g_date_free
1861 * Returns: %TRUE, if a date was copied, %FALSE if the tag didn't exist in the
1862 * given list or if it was %NULL.
1865 gst_tag_list_get_date (const GstTagList * list, const gchar * tag,
1870 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1871 g_return_val_if_fail (tag != NULL, FALSE);
1872 g_return_val_if_fail (value != NULL, FALSE);
1874 if (!gst_tag_list_copy_value (&v, list, tag))
1876 *value = (GDate *) g_value_dup_boxed (&v);
1878 return (*value != NULL);
1882 * gst_tag_list_get_date_index:
1883 * @list: a #GstTagList to get the tag from
1884 * @tag: tag to read out
1885 * @index: number of entry to read out
1886 * @value: (out callee-allocates) (transfer full): location for the result
1888 * Gets the date that is at the given index for the given tag in the given
1889 * list and copies it into the variable pointed to by @value. Free the date
1890 * with g_date_free() when it is no longer needed.
1892 * Free-function: g_date_free
1894 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1895 * given list or if it was %NULL.
1898 gst_tag_list_get_date_index (const GstTagList * list,
1899 const gchar * tag, guint index, GDate ** value)
1903 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1904 g_return_val_if_fail (tag != NULL, FALSE);
1905 g_return_val_if_fail (value != NULL, FALSE);
1907 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1909 *value = (GDate *) g_value_dup_boxed (v);
1910 return (*value != NULL);
1914 * gst_tag_list_get_date_time:
1915 * @list: a #GstTagList to get the tag from
1916 * @tag: tag to read out
1917 * @value: (out callee-allocates) (transfer full): address of a #GstDateTime
1918 * pointer variable to store the result into
1920 * Copies the first datetime for the given tag in the taglist into the variable
1921 * pointed to by @value. Unref the date with gst_date_time_unref() when
1922 * it is no longer needed.
1924 * Free-function: gst_date_time_unref
1926 * Returns: %TRUE, if a datetime was copied, %FALSE if the tag didn't exist in
1927 * the given list or if it was %NULL.
1930 gst_tag_list_get_date_time (const GstTagList * list, const gchar * tag,
1931 GstDateTime ** value)
1935 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1936 g_return_val_if_fail (tag != NULL, FALSE);
1937 g_return_val_if_fail (value != NULL, FALSE);
1939 if (!gst_tag_list_copy_value (&v, list, tag))
1942 *value = (GstDateTime *) g_value_dup_boxed (&v);
1944 return (*value != NULL);
1948 * gst_tag_list_get_date_time_index:
1949 * @list: a #GstTagList to get the tag from
1950 * @tag: tag to read out
1951 * @index: number of entry to read out
1952 * @value: (out callee-allocates) (transfer full): location for the result
1954 * Gets the datetime that is at the given index for the given tag in the given
1955 * list and copies it into the variable pointed to by @value. Unref the datetime
1956 * with gst_date_time_unref() when it is no longer needed.
1958 * Free-function: gst_date_time_unref
1960 * Returns: %TRUE, if a value was copied, %FALSE if the tag didn't exist in the
1961 * given list or if it was %NULL.
1964 gst_tag_list_get_date_time_index (const GstTagList * list,
1965 const gchar * tag, guint index, GstDateTime ** value)
1969 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
1970 g_return_val_if_fail (tag != NULL, FALSE);
1971 g_return_val_if_fail (value != NULL, FALSE);
1973 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
1975 *value = (GstDateTime *) g_value_dup_boxed (v);
1976 return (*value != NULL);
1980 * gst_tag_list_get_sample:
1981 * @list: a #GstTagList to get the tag from
1982 * @tag: tag to read out
1983 * @sample: (out callee-allocates) (transfer full): address of a GstSample
1984 * pointer variable to store the result into
1986 * Copies the first sample for the given tag in the taglist into the variable
1987 * pointed to by @sample. Free the sample with gst_sample_unref() when it is
1988 * no longer needed. You can retrieve the buffer from the sample using
1989 * gst_sample_get_buffer() and the associated caps (if any) with
1990 * gst_sample_get_caps().
1992 * Free-function: gst_sample_unref
1994 * Returns: %TRUE, if a sample was returned, %FALSE if the tag didn't exist in
1995 * the given list or if it was %NULL.
1998 gst_tag_list_get_sample (const GstTagList * list, const gchar * tag,
1999 GstSample ** sample)
2003 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
2004 g_return_val_if_fail (tag != NULL, FALSE);
2005 g_return_val_if_fail (sample != NULL, FALSE);
2007 if (!gst_tag_list_copy_value (&v, list, tag))
2009 *sample = g_value_dup_boxed (&v);
2011 return (*sample != NULL);
2015 * gst_tag_list_get_sample_index:
2016 * @list: a #GstTagList to get the tag from
2017 * @tag: tag to read out
2018 * @index: number of entry to read out
2019 * @sample: (out callee-allocates) (transfer full): address of a GstSample
2020 * pointer variable to store the result into
2022 * Gets the sample that is at the given index for the given tag in the given
2023 * list and copies it into the variable pointed to by @sample. Free the sample
2024 * with gst_sample_unref() when it is no longer needed. You can retrieve the
2025 * buffer from the sample using gst_sample_get_buffer() and the associated
2026 * caps (if any) with gst_sample_get_caps().
2028 * Free-function: gst_sample_unref
2030 * Returns: %TRUE, if a sample was copied, %FALSE if the tag didn't exist in the
2031 * given list or if it was %NULL.
2034 gst_tag_list_get_sample_index (const GstTagList * list,
2035 const gchar * tag, guint index, GstSample ** sample)
2039 g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE);
2040 g_return_val_if_fail (tag != NULL, FALSE);
2041 g_return_val_if_fail (sample != NULL, FALSE);
2043 if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL)
2045 *sample = g_value_dup_boxed (v);
2046 return (*sample != NULL);